Repository navigation
Fix IllegalStateException when typing an unterminated string in Go - #9660
Open
emilianbold wants to merge 1 commit into
Open
emilianbold wants to merge 1 commit into
emilianbold wants to merge 1 commit into
Conversation
…pache#9654) Typing a double quote as the last characters of a Go document made the lexer infrastructure throw: IllegalStateException: Lexer ...GoLangLexer returned null token but lexerInput.readLength()=6 Root cause: an unterminated literal at the end of the text makes the ANTLR lexer throw LexerNoViableAltException, after which it emits an end-of-input token while characters are still pending on the LexerInput. AbstractAntlrLexerBridge.nextToken() then returned null, but the consumed characters still needed a token. Fix it once in AbstractAntlrLexerBridge: when the ANTLR lexer reports end of input with pending input, delegate to mapToken() so the pending characters receive a token (implementations map EOF to an error-ish token in their default branch). A true end of input (readLength()==0) still returns null as before. Also fix TomlLexer.mapToken(), the only override of the nine ANTLR-backed languages that explicitly returned null for EOF, so it returns an ERROR token instead. Adds GoLangLexerTest as a regression test covering the issue text, unterminated rune and raw string literals, and that well formed text stays unaffected. Assisted-by: mimo-v2.6-flash-free
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The shared lexer fix is consistent with existing mappings and is covered by focused regression tests.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes unterminated Go strings causing lexer failures by tokenizing pending input at EOF.
Changes:
- Maps EOF with pending characters through each lexer’s token mapping.
- Handles TOML EOF as an error token.
- Adds Go lexer regression tests and JUnit support.
| File | Description |
|---|---|
AbstractAntlrLexerBridge.java |
Handles pending input at EOF. |
TomlLexer.java |
Maps pending EOF input to ERROR. |
GoLangLexerTest.java |
Adds lexer regression coverage. |
project.xml |
Adds JUnit 4 test dependency. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Member
|
"Secret" lock and unlock trick to pick up labels. 😄 |
mbien
reviewed
Oct 6, 2026
Comment on lines
+67
to
+76
| private static final String ISSUE_9654_TEXT = "package main\n" | ||
| + "\n" | ||
| + "import (\n" | ||
| + " \"fmt\"\n" | ||
| + ")\n" | ||
| + "\n" | ||
| + "func main() {\n" | ||
| + " fmt.Println(\")\n" | ||
| + "}\n" | ||
| + "\n"; |
Member
There was a problem hiding this comment.
lets use multi line strings for new tests. I just converted the maven tests -> much easier to read once something fails.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9654
In AbstractAntlrLexerBridge: when the ANTLR lexer reports end of input with pending input, delegate to mapToken() so the pending characters receive a token (implementations map EOF to an error-ish token in their default branch). A true end of input (readLength()==0) still returns null as before.
Assisted-by: mimo-v2.6-flash-free
^Add meaningful description above
Click to collapse/expand PR instructions
By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
LLMs, Commit messages and PR description:
git log) that all commits have a valid name and email address for you in the Author field.Assisted-by: MODEL_NAME MODEL_VERSIONline appended to the commit message.Assisted-byline from above)If you're a first time contributor, see the Contributing guidelines for more information.
If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.
PR approval and merge checklist:
If this PR targets the delivery branch: don't merge. (full wiki article)