Skip to content

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

Merged
mbien merged 1 commit into
apache:masterfrom
emilianbold:fix-9654-go-lexer-null-token
Oct 15, 2026
Merged

mbien merged 1 commit into
apache:masterfrom
emilianbold:fix-9654-go-lexer-null-token

Conversation

@emilianbold

@emilianbold emilianbold commented Oct 4, 2026 •

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.

Also adds the module's first tests (GoLangLexerTest, covering the issue text plus unterminated rune and raw string literals) and lists ide/languages.go in the CI workflow (.github/workflows/main.yml) next to the other languages.* modules so they run on CI.

Assisted-by: mimo-v2.6-flash-free
Assisted-by: DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix-0731 (on ds4j)
Assisted-by: GLM-5.3 (CI workflow entry, squash)


^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)

@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. 😄

@emilianbold
emilianbold requested a review from mbien October 14, 2026 05:41
@neilcsmith-net neilcsmith-net added this to the NB32 milestone Oct 14, 2026
@neilcsmith-net

Copy link
Copy Markdown
Member

@mbien looks a good thing to get in to NB32. Is it me, or are we not running languages.go tests in CI currently?

@mbien

mbien commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Is it me, or are we not running languages.go tests in CI currently?

I think the module didn't have any tests -> must be still added to the main.yaml

edit: also please squash to a commit you want to see in the repo

@neilcsmith-net

Copy link
Copy Markdown
Member

Ah, yes, missed that this had no tests before this PR. OK, @emilianbold can you add in to main.yaml next to the other lDE language tests, then squash, so we can get the tests run on CI before merging?

If this misses today's freeze cutoff I'd be inclined to re-target to delivery to get this into RC2.

@emilianbold
emilianbold force-pushed the fix-9654-go-lexer-null-token branch from 8c84229 to ed92805 Compare October 15, 2026 09:37
@emilianbold

Copy link
Copy Markdown
Member Author

Added ide/languages.go to main.yml (in the ide-modules-test job, between languages.env and languages.hcl) and squashed to a single commit. Tests pass locally (6/6, ant -f ide/languages.go test); CI is running now.

cc @neilcsmith-net @mbien — regarding the freeze cutoff / RC2: should this be re-targeted to delivery?

@mbien mbien left a comment

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.

its fine. you squashed it in time :)

…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.

Also add the languages.go test job to the CI workflow
(.github/workflows/main.yml), next to the other languages.* modules;
the module had no entry there because it had no tests before this PR.

Assisted-by: mimo-v2.6-flash-free
Assisted-by: DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix-0731 (on ds4j)
Assisted-by: GLM-5.3
@emilianbold
emilianbold force-pushed the fix-9654-go-lexer-null-token branch from ed92805 to 7ddb1bc Compare October 15, 2026 09:39
@emilianbold

Copy link
Copy Markdown
Member Author

OK, I guess you have to merge it no?

@mbien
mbien merged commit 7cde705 into apache:master Oct 15, 2026
31 of 33 checks passed
@mbien

mbien commented Oct 15, 2026

Copy link
Copy Markdown
Member

i can merge it. thought your account has repo access?

the rule about not merging would be if it targets delivery. In that case release managers decide since it could cause conflicts etc. delivery didn't branch yet.

@emilianbold

Copy link
Copy Markdown
Member Author

i can merge it. thought your account has repo access?

Thank you. I haven't committed here in a while so I didn't want to overstep.

@mbien

mbien commented Oct 15, 2026

Copy link
Copy Markdown
Member

ah. no worries. thanks for fixing the go issue and welcome back :)

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