diff --git a/src/main/java/org/sablecc/sablecc/lexer/Lexer.java b/src/main/java/org/sablecc/sablecc/lexer/Lexer.java index 9e9639c55eedd82894e0b39217beeeb9973bc93a..d053187517e7460bfd7e9a24880e1768c0d1fcc9 100644 --- a/src/main/java/org/sablecc/sablecc/lexer/Lexer.java +++ b/src/main/java/org/sablecc/sablecc/lexer/Lexer.java @@ -1014,9 +1014,12 @@ public class Lexer implements ITokenListContainer { try { - DataInputStream s = new DataInputStream( - new BufferedInputStream( - Lexer.class.getResourceAsStream("lexer.dat"))); + InputStream resStream = Lexer.class.getResourceAsStream("lexer.dat"); + if(resStream == null) + { + throw new RuntimeException("The file \"lexer.dat\" is missing."); + } + DataInputStream s = new DataInputStream(new BufferedInputStream(resStream)); // read gotoTable int length = s.readInt(); @@ -1054,9 +1057,9 @@ public class Lexer implements ITokenListContainer s.close(); } - catch(Exception e) + catch(IOException e) { - throw new RuntimeException("The file \"lexer.dat\" is either missing or corrupted."); + throw new RuntimeException("The file \"lexer.dat\" is either missing or corrupted.", e); } } } diff --git a/src/main/java/org/sablecc/sablecc/parser/Parser.java b/src/main/java/org/sablecc/sablecc/parser/Parser.java index 201e9863d88ce9a696890d23d9b7aeb3c253ab19..f76e51c6bbbc10ca95dc63718f2602da919fbf2c 100644 --- a/src/main/java/org/sablecc/sablecc/parser/Parser.java +++ b/src/main/java/org/sablecc/sablecc/parser/Parser.java @@ -11,6 +11,7 @@ import de.hhu.stups.sablecc.patch.*; import java.io.DataInputStream; import java.io.BufferedInputStream; +import java.io.InputStream; import java.io.IOException; @SuppressWarnings({"rawtypes","unchecked","unused"}) @@ -10642,9 +10643,12 @@ public class Parser implements IParser { try { - DataInputStream s = new DataInputStream( - new BufferedInputStream( - Parser.class.getResourceAsStream("parser.dat"))); + InputStream resStream = Parser.class.getResourceAsStream("parser.dat"); + if(resStream == null) + { + throw new RuntimeException("The file \"parser.dat\" is missing."); + } + DataInputStream s = new DataInputStream(new BufferedInputStream(resStream)); // read actionTable int length = s.readInt(); @@ -10703,9 +10707,9 @@ public class Parser implements IParser s.close(); } - catch(Exception e) + catch(IOException e) { - throw new RuntimeException("The file \"parser.dat\" is either missing or corrupted."); + throw new RuntimeException("The file \"parser.dat\" is either missing or corrupted.", e); } } } diff --git a/src/main/resources/org/sablecc/sablecc/lexer.txt b/src/main/resources/org/sablecc/sablecc/lexer.txt index 061cec69600d50a6af74fc33c3a9cb5d65f15224..2922cf10ee42c337b32f2f01d194648325a5795e 100644 --- a/src/main/resources/org/sablecc/sablecc/lexer.txt +++ b/src/main/resources/org/sablecc/sablecc/lexer.txt @@ -412,9 +412,12 @@ Macro:LexerTail { try { - DataInputStream s = new DataInputStream( - new BufferedInputStream( - Lexer.class.getResourceAsStream("lexer.dat"))); + InputStream resStream = Lexer.class.getResourceAsStream("lexer.dat"); + if(resStream == null) + { + throw new RuntimeException("The file \"lexer.dat\" is missing."); + } + DataInputStream s = new DataInputStream(new BufferedInputStream(resStream)); // read gotoTable int length = s.readInt(); @@ -452,9 +455,9 @@ Macro:LexerTail s.close(); } - catch(Exception e) + catch(IOException e) { - throw new RuntimeException("The file \"lexer.dat\" is either missing or corrupted."); + throw new RuntimeException("The file \"lexer.dat\" is either missing or corrupted.", e); } } } diff --git a/src/main/resources/org/sablecc/sablecc/parser.txt b/src/main/resources/org/sablecc/sablecc/parser.txt index 9873f8314d2106b578395508002f0f6ce0d2eb44..862ac91403b9e7959abd031ce47c6b7a343d1e4e 100644 --- a/src/main/resources/org/sablecc/sablecc/parser.txt +++ b/src/main/resources/org/sablecc/sablecc/parser.txt @@ -19,6 +19,7 @@ import de.hhu.stups.sablecc.patch.*; import java.io.DataInputStream; import java.io.BufferedInputStream; +import java.io.InputStream; import java.io.IOException; @SuppressWarnings({"rawtypes","unchecked","unused"}) @@ -504,9 +505,12 @@ Macro:ParserTail { try { - DataInputStream s = new DataInputStream( - new BufferedInputStream( - Parser.class.getResourceAsStream("parser.dat"))); + InputStream resStream = Parser.class.getResourceAsStream("parser.dat"); + if(resStream == null) + { + throw new RuntimeException("The file \"parser.dat\" is missing."); + } + DataInputStream s = new DataInputStream(new BufferedInputStream(resStream)); // read actionTable int length = s.readInt(); @@ -565,9 +569,9 @@ Macro:ParserTail s.close(); } - catch(Exception e) + catch(IOException e) { - throw new RuntimeException("The file \"parser.dat\" is either missing or corrupted."); + throw new RuntimeException("The file \"parser.dat\" is either missing or corrupted.", e); } } }