NullPointerException in LexerGrammar.createLexerInterpreter() on invalid grammar
- Dominant language
- Java
- Stars
- 19k
- Forks
- 3.5k
- PR merge metrics
- No merged PRs in 30d
Description
When creating a grammar that is missing a single quote to close a token, not getting a proper exception.
Instead, getting a NullPointerException when trying to actually use the lexer.
Sample test code (JUnit):
```java
@Test
public void bugReproduction() throws Exception {
String grammarWithMissingQuote = "grammar test;\nr0: r1+;\nr1: 'ABC' | 'ABCDE;";
LexerGrammar lg = new LexerGrammar(grammarWithMissingQuote);
CharStream inputStream = CharStreams.fromReader(new StringReader("AB"));
lg.createLexerInterpreter(inputStream);
}
```
This throws NullPointerException straight out of Grammar.createLexerInterpreter at line 1299, due to ```implicitLexer``` not being initialized. I would expect the LexerGrammar constructor to throw instead of succeeding but not really initializing.
Contributor guide
Research direction
Start with the JUnit reproduction in the issue and inspect LexerGrammar.createLexerInterpreter, Grammar.createLexerInterpreter, and the LexerGrammar constructor. Run the reproduction with the grammar containing the missing quote. Done means invalid grammars produce a proper exception during construction or use, rather than a NullPointerException caused by an uninitialized implicitLexer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100