Java dies with NullPointerException during comple of .ino file

This happens randomly. The IDE throws out an error (or more), like "'nono' was not declared in this scope" and then I see:

xit status 1
Exception in thread "Thread-179" java.lang.NullPointerException
	at org.fife.ui.rsyntaxtextarea.TokenMakerBase.addToken(TokenMakerBase.java:136)
	at processing.app.syntax.SketchTokenMaker.addToken(SketchTokenMaker.java:73)
	at org.fife.ui.rsyntaxtextarea.TokenMakerBase.addToken(TokenMakerBase.java:110)
	at org.fife.ui.rsyntaxtextarea.modes.CPlusPlusTokenMaker.addToken(CPlusPlusTokenMaker.java:1868)
	at org.fife.ui.rsyntaxtextarea.modes.CPlusPlusTokenMaker.addToken(CPlusPlusTokenMaker.java:1852)
	at org.fife.ui.rsyntaxtextarea.modes.CPlusPlusTokenMaker.addToken(CPlusPlusTokenMaker.java:1841)
	at org.fife.ui.rsyntaxtextarea.modes.CPlusPlusTokenMaker.yylex(CPlusPlusTokenMaker.java:2241)
	at org.fife.ui.rsyntaxtextarea.modes.CPlusPlusTokenMaker.getTokenList(CPlusPlusTokenMaker.java:1919)
	at org.fife.ui.rsyntaxtextarea.RSyntaxDocument.getTokenListForLine(RSyntaxDocument.java:431)
	at org.fife.ui.rsyntaxtextarea.SyntaxView.modelToView(SyntaxView.java:541)
	at javax.swing.plaf.basic.BasicTextUI$RootView.modelToView(BasicTextUI.java:1509)
	at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:1047)
	at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:1022)
	at javax.swing.text.JTextComponent.modelToView(JTextComponent.java:1377)
	at org.fife.ui.rtextarea.RTextAreaBase.possiblyUpdateCurrentLineHighlightLocation(RTextAreaBase.java:778)
	at org.fife.ui.rtextarea.RTextArea.fireCaretUpdate(RTextArea.java:614)
	at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.fireCaretUpdate(RSyntaxTextArea.java:835)
	at javax.swing.text.JTextComponent$MutableCaretEvent.fire(JTextComponent.java:4394)
	at javax.swing.text.JTextComponent$MutableCaretEvent.stateChanged(JTextComponent.java:4416)
	at javax.swing.text.DefaultCaret.fireStateChanged(DefaultCaret.java:802)
	at javax.swing.text.DefaultCaret.changeCaretPosition(DefaultCaret.java:1274)
	at javax.swing.text.DefaultCaret.handleSetDot(DefaultCaret.java:1173)
	at javax.swing.text.DefaultCaret$DefaultFilterBypass.setDot(DefaultCaret.java:1913)
	at javax.swing.text.NavigationFilter.setDot(NavigationFilter.java:64)
	at org.fife.ui.rtextarea.ConfigurableCaret$FoldAwareNavigationFilter.setDot(ConfigurableCaret.java:724)
	at javax.swing.text.DefaultCaret.setDot(DefaultCaret.java:1151)
	at javax.swing.text.DefaultCaret.setDot(DefaultCaret.java:1051)
	at javax.swing.text.JTextComponent.setCaretPosition(JTextComponent.java:1631)
	at processing.app.Editor.addLineHighlight(Editor.java:1665)
	at processing.app.Editor.statusError(Editor.java:2546)
	at processing.app.Editor$BuildHandler.run(Editor.java:1640)
	at java.lang.Thread.run(Thread.java:748)

This is running on a Mint 20 desktop,

java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)
uname -a
Linux rustburg-pc 5.4.0-81-generic #91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Arduino 1.8.13.

It doesn't fail every time, but it's often enough to get annoying. The fix is to close all the IDE windows and restart the IDE.
Any suggestions would be appreciated.
I've fought with this error for a number of years. Mostly Debian/Ubuntu based systems and open JDK.
Thanks, Jim

Is this an expected error caused by a problem in your sketch code?

It looks somewhat similar to the error output from this bug report:

I wonder if it's the same?

It is an expected error. It's a normal error when you forget to declare a variable. It's not the same. In that case, the IDE continues to run. In my case, the IDE is hung and doesn't respond. I think it's a fatal Java error.

Jim

OK, that also matches with the bug report I linked to above.

Can you provide a minimal sketch that will trigger the bug? Something like this:

void setup() {
  foo = 42;
}
void loop() {}

I'll try but I would be surprised if it fails on a simple sketch. My project is over 5K lines of code.

Oof. It is challenging to investigate this sort of bug that occurs inconsistently and only with a complex setup. The first step in the process must be to reproduce the issue and then to bisect it. If you can distill it down to a very minimal demonstration that will still reproduce the problem then often the cause becomes clear. But we aren't always to fortunate to have well behaved bugs that allow such a thing.

I have a 62 line program that just failed with a null pointer exception. Is that minimal enough?

One time it threw a Null Pointer Exception but didn't abort or hang the IDE. Another time it gave me this message:
Exception in thread "AWT-EventQueue-0" no matching function for call to 'Revent::bindCallback(void (&)())'

Just now it hung the IDE with a Null Pointer Exception. Compile it enough times and I think it will fail. I'll try to upload it.

[Event.ino|attachment]
(upload://cqhbdat3a5SL0Py8HCMp7ivYZNc.ino) (1.0 KB)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.