Skip to content

Fix IllegalStateException when typing an unterminated string in Go - #9660

Open
emilianbold wants to merge 1 commit into
apache:masterfrom
emilianbold:fix-9654-go-lexer-null-token
Open

emilianbold wants to merge 1 commit into
apache:masterfrom
emilianbold:fix-9654-go-lexer-null-token

Conversation

@emilianbold

Copy link
Copy Markdown
Member

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 -

  • are all your own work, and you have the right to contribute them.
  • are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).

LLMs, Commit messages and PR description:

  • Please make sure (eg. git log) that all commits have a valid name and email address for you in the Author field.
  • LLM assisted commits should be attributed with an Assisted-by: MODEL_NAME MODEL_VERSION line appended to the commit message.
    • Please mention coding assistance in the PR description too (eg. by adding the same Assisted-by line from above)
    • Please describe the changes in your own words - we'd like to know you understand the changes being made!

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:

  1. Was this PR correctly labeled, did the right tests run? When did they run?
  2. Is this PR squashed?
  3. Are author name / email address correct? Are co-authors correctly listed? Do the commit messages need updates?
  4. Does the PR title and description still fit after the Nth iteration? Is the description sufficient to appear in the release notes?

If this PR targets the delivery branch: don't merge. (full wiki article)

…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
@emilianbold emilianbold self-assigned this Oct 4, 2026
@emilianbold emilianbold added Go Go Language kind:bug Bug report or fix labels Oct 4, 2026
@emilianbold
emilianbold requested a balanced review from Copilot October 4, 2026 19:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@emilianbold emilianbold added the Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) label Oct 4, 2026
@apache apache locked and limited conversation to collaborators Oct 5, 2026
@apache apache unlocked this conversation Oct 5, 2026
@neilcsmith-net

Copy link
Copy Markdown
Member

"Secret" lock and unlock trick to pick up labels. 😄

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";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use multi line strings for new tests. I just converted the maven tests -> much easier to read once something fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Go Go Language Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) kind:bug Bug report or fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ISE caused by GoLangLexer returning null token when typing double-quote (")

4 participants