Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix case when ANTLR getText() causes assertion in LexerInput. #5619

Merged
merged 1 commit into from
Mar 8, 2023

Conversation

lkishalmi
Copy link
Contributor

It seems getText() calls (only seen at error handling so far) from ANTLR could cause and assertion at LexerInput.readText()

This PR makes sure that we call the readText method with arguments that satisfy that condition.

@lkishalmi lkishalmi added the ANTLR label Mar 7, 2023
@lkishalmi lkishalmi added this to the NB18 milestone Mar 7, 2023
Copy link
Contributor

@vieiro vieiro left a comment

Choose a reason for hiding this comment

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

Hi @lkishalmi ,

I tried this with the current RustLexer (removing the EOF trick and doing some other adjustments) and I can see no more AssertionErrors now.

I'm getting some other errors [1], though. But maybe those are rust-lexer specific (I'll try to investigate during the weekend, maybe I can create a small grammar with some test case).

So a green light for me to merge this.

Thanks,
Antonio

[1]

java.lang.IllegalStateException: Lexer org.netbeans.modules.rust.grammar.RustLanguageLexer@4c0625c8
  returned null token but lexerInput.readLength()=13
  lexer-state: -1
  tokenStartOffset=3224, readOffset=3237, lookaheadOffset=3238
  Chars: "", x, z);\n}\n\n" - these characters need to be tokenized.
Fix the lexer to not return null token in this state.
	at org.netbeans.lib.lexer.LexerInputOperation.checkLexerInputFinished(LexerInputOperation.java:435)
	at org.netbeans.lib.lexer.LexerInputOperation.nextToken(LexerInputOperation.java:193)
	at org.netbeans.lib.lexer.inc.TokenListUpdater.relex(TokenListUpdater.java:602)
	at org.netbeans.lib.lexer.inc.TokenListUpdater.updateRegular(TokenListUpdater.java:255)
	at org.netbeans.lib.lexer.inc.TokenHierarchyUpdate$UpdateItem.update(TokenHierarchyUpdate.java:325)
	at org.netbeans.lib.lexer.inc.TokenHierarchyUpdate.processLevelInfos(TokenHierarchyUpdate.java:200)
	at org.netbeans.lib.lexer.inc.TokenHierarchyUpdate.updateImpl(TokenHierarchyUpdate.java:171)
	at org.netbeans.lib.lexer.inc.TokenHierarchyUpdate.update(TokenHierarchyUpdate.java:109)
	at org.netbeans.lib.lexer.TokenHierarchyOperation.textModified(TokenHierarchyOperation.java:585)
	at org.netbeans.spi.lexer.TokenHierarchyControl.textModified(TokenHierarchyControl.java:71)
	at org.netbeans.lib.lexer.inc.DocumentInput.textModified(DocumentInput.java:128)
	at org.netbeans.lib.lexer.inc.DocumentInput.insertUpdate(DocumentInput.java:117)
	at org.netbeans.lib.editor.util.swing.PriorityDocumentListenerList.insertUpdate(PriorityDocumentListenerList.java:60)
	at java.desktop/javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:203)
	at org.netbeans.editor.BaseDocument.fireInsertUpdate(BaseDocument.java:1654)
	at org.netbeans.editor.BaseDocument.handleInsertString(BaseDocument.java:826)

@lkishalmi lkishalmi merged commit 34f880e into apache:master Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants