Repository navigation
Netbeans cannot delete some text when editing TOML files #8174
Copy link
Copy link
Closed
Labels
Description
Apache NetBeans version
Apache NetBeans 24
What happened
When editing TOML files for Gradle projects the editor hangs if there is a temporary syntax error in the files. At first the editor won't let me type anything within unmatched curly braces. Deleting the braces is also not possible. Under some circumstances the entire editor (and netbeans) hangs (endless loop). I get the following or similar exceptions:
java.lang.IllegalStateException: Lexer org.netbeans.modules.languages.toml.TomlLexer@4eeb0fe6
returned null token but lexerInput.readLength()=2
lexer-state: -1
tokenStartOffset=1778, readOffset=1780, lookaheadOffset=1781
Chars: "\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.IncTokenList.tokenOrEmbeddingImpl(IncTokenList.java:170)
at org.netbeans.lib.lexer.inc.IncTokenList.tokenOrEmbedding(IncTokenList.java:165)
at org.netbeans.api.lexer.TokenSequence.moveNext(TokenSequence.java:458)
at org.netbeans.modules.textmate.lexer.SyntaxHighlighting$TSInfo.moveNextToken(SyntaxHighlighting.java:785)
at org.netbeans.modules.textmate.lexer.SyntaxHighlighting$HSImpl.moveTheSequence(SyntaxHighlighting.java:482)
at org.netbeans.modules.textmate.lexer.SyntaxHighlighting$HSImpl.moveNext(SyntaxHighlighting.java:431)
at org.netbeans.modules.editor.lib2.highlighting.DirectMergeContainer$Wrapper.fetchNextHighlight(DirectMergeContainer.java:600)
at org.netbeans.modules.editor.lib2.highlighting.DirectMergeContainer$HlSequence.updateMergeVars(DirectMergeContainer.java:337)
at org.netbeans.modules.editor.lib2.highlighting.DirectMergeContainer$HlSequence.nextMerge(DirectMergeContainer.java:303)
at org.netbeans.modules.editor.lib2.highlighting.DirectMergeContainer$HlSequence.moveNext(DirectMergeContainer.java:234)
at org.netbeans.modules.editor.lib2.highlighting.HighlightsReader.readUntil(HighlightsReader.java:59)
at org.netbeans.modules.editor.lib2.view.HighlightsViewFactory.restart(HighlightsViewFactory.java:168)
at org.netbeans.modules.editor.lib2.view.ViewBuilder$FactoryState.init(ViewBuilder.java:1299)
at org.netbeans.modules.editor.lib2.view.ViewBuilder.createViews(ViewBuilder.java:699)
at org.netbeans.modules.editor.lib2.view.ViewBuilder.createReplaceRepaintViews(ViewBuilder.java:660)
at org.netbeans.modules.editor.lib2.view.ViewUpdates.reinitAllViews(ViewUpdates.java:189)
at org.netbeans.modules.editor.lib2.view.DocumentViewOp.checkViewsInited(DocumentViewOp.java:621)
at org.netbeans.modules.editor.lib2.view.DocumentView.getPreferredSpan(DocumentView.java:226)
at java.desktop/javax.swing.plaf.basic.BasicTextUI$RootView.getPreferredSpan(BasicTextUI.java:1454)
at java.desktop/javax.swing.plaf.basic.BasicTextUI.getPreferredSize(BasicTextUI.java:950)
at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1734)
at java.desktop/javax.swing.JEditorPane.getPreferredSize(JEditorPane.java:1390)
at org.netbeans.modules.editor.NbEditorUI$LayeredEditorPane.getPreferredSize(NbEditorUI.java:454)
at java.desktop/javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:799)
at com.formdev.flatlaf.ui.FlatScrollPaneUI$FlatScrollPaneLayout.layoutContainer(FlatScrollPaneUI.java:563)
at java.desktop/java.awt.Container.layout(Container.java:1541)
at java.desktop/java.awt.Container.doLayout(Container.java:1530)
at java.desktop/java.awt.Container.validateTree(Container.java:1725)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validate(Container.java:1660)
at org.netbeans.core.windows.view.ui.DesktopImpl$LayeredLayout.layoutContainer(DesktopImpl.java:529)
at java.desktop/java.awt.Container.layout(Container.java:1541)
at java.desktop/java.awt.Container.doLayout(Container.java:1530)
at java.desktop/java.awt.Container.validateTree(Container.java:1725)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validateTree(Container.java:1734)
at java.desktop/java.awt.Container.validate(Container.java:1660)
at java.desktop/javax.swing.RepaintManager$3.run(RepaintManager.java:757)
at java.desktop/javax.swing.RepaintManager$3.run(RepaintManager.java:755)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.desktop/javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:754)
at java.desktop/javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1896)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:136)
[catch] at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Language / Project Type / NetBeans Component
Gradle multi-project
How to reproduce
Copy the following content in the editor (*.toml) and delete the last brace. It wont get deleted because of an exception. Worse can happen if the you add or delete other braces.
[plugins]
jooq-codegen = { id = "org.jooq.jooq-codegen-gradle", version.ref="jooq" }
Did this work correctly in an earlier version?
No / Don't know
Operating System
Windows 10
JDK
Java 21
Apache NetBeans packaging
Apache NetBeans binary zip
Anything else
No response
Are you willing to submit a pull request?
No
Reactions are currently unavailable
Activity
matthiasblaesing commentedon Jan 22, 2025
Reproducible, @lkishalmi @vieiro could you please have a look?
lkishalmi commentedon Jan 22, 2025
Checking.
lkishalmi commentedon Jan 22, 2025
Could not reproduce. However there is something weird in the stacktrace above.
It has references of
org.netbeans.modules.textmate.lexer.SyntaxHighlightingwhich should not be there.Is it possibe that some TextMate grammar get registered in that mime-path?
[-]Netbeans hangs when editing TOML files[/-][+]Netbeans cannot delete some text when editing TOML files[/+]vieiro commentedon Jan 23, 2025
Hi, I can see what @niabot says. In my case NetBeans does not "hang", but can't delete the last
}in the given example.I'll try to take a look at it later on.
For the record, here's the message I get in the IDE Log:
vieiro commentedon Jan 23, 2025
I think this may happen in any other
antlr4lexers. The bridge hiccups when the lexer returnsnullfor a token (due to a lexer/parsing error).This does not mean that the
antlr4grammar is wrong. Theantlr4[lexer] grammar works correctly for correct files, but can't handle a file with a missing}, for example. Forantlr4grammars to work correctly with the antlr editor bridge, the grammars must contemplate an "error" token and not just returnnullon incorrect files.niabot commentedon Jan 24, 2025
@vieiro The simple example (deleting the last curly brace) did not "hang" Netbeans. But i also managed to get it stuck in an infinite loop by copying/cutting text. This was my workaround for not being able to type or delete a curly brace. This intial bug might have triggered another bug/effect down the line, but i have no stacktrace/exception of it.
1 remaining item
lkishalmi commentedon Jan 24, 2025
Managed to reproduce. The issue is in the ANTLR Lexer for TOML
To reproduce just have the following toml:
a = {}then delete the last curly from right with
<backspace>.The problem is that ANTLR sends an EOF token in this case, while still having some characters on the stream.
I can try to patch the bridge to handle this cases better, though it would be the best to fix the TOML Lexer grammar.
lkishalmi commentedon Jan 24, 2025
@vieiro I see this PR in your project. vieiro/toml-java#18
That could help. Also each
modeshall have an rule at the end that matches everything, maps toINVALID_TYPEand/or pops from the mode.vieiro commentedon Jan 24, 2025
Thanks @lkishalmi . I'll create a new PR that will help. Basically the lexer will have to return an "error" token whenever an invalid character is found. I'll explain during the weekend.
vieiro commentedon Jan 24, 2025
That'd be a requirement for all
antlr4grammars that we currently use. Therustgrammar does indeed detect these error cases too, IIRC.apache#8174: Bump ide/libs.tomljava
vieiro commentedon Jan 25, 2025
Well, there we go this change
We may want to update the
antlrtutorial to explain that antlr4 lexers should contemplate error situation (such as this: a TOML inline table without an ending}) and return this "error token" (INVALID_VALUEin this case). That makes it easier forAntlrLexerBridgeto map that token to an ERROR. Just throwing/capturing an exception in Antlr is not good enough for us.vieiro commentedon Jan 25, 2025
Hi @niabot , the "hang" you are detecting may be due to your specific setup. As @lkishalmi explains you seem to have a
texmatehighlighing layer that may be interferring/blocking. Next time you can usejconsoleor ajps+jstackcombination to fetch an stack trace for us, and report again.matthiasblaesing commentedon Jan 25, 2025
@vieiro @lkishalmi I don't think your assessment is correct, that the user did something special. Have a look here:
netbeans/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/SyntaxHighlighting.java
Lines 851 to 871 in ab20d9a
My reading of this is, that the textmate syntax hightlighter will always run (registered on the empty mimetype). These problem show up at all the locations where the tokensquence is iterated, for the reporter that was syntax highlighting.
vieiro commentedon Jan 25, 2025
Yep, thanks @matthiasblaesing. We couldn't reproduce the hang with the stacktrace provides, if the fix does not solve the problem then we'll need to reopen with a stack trace.
apache#8174: Bump ide/libs.tomljava
apache#8174: Bump ide/libs.tomljava
apache#8174: Bump ide/libs.tomljava
Merge pull request #8192 from vieiro/hotfix/8174