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(
	at org.fife.ui.rsyntaxtextarea.TokenMakerBase.addToken(
	at org.fife.ui.rsyntaxtextarea.modes.CPlusPlusTokenMaker.addToken(
	at org.fife.ui.rsyntaxtextarea.modes.CPlusPlusTokenMaker.addToken(
	at org.fife.ui.rsyntaxtextarea.modes.CPlusPlusTokenMaker.addToken(
	at org.fife.ui.rsyntaxtextarea.modes.CPlusPlusTokenMaker.yylex(
	at org.fife.ui.rsyntaxtextarea.modes.CPlusPlusTokenMaker.getTokenList(
	at org.fife.ui.rsyntaxtextarea.RSyntaxDocument.getTokenListForLine(
	at org.fife.ui.rsyntaxtextarea.SyntaxView.modelToView(
	at javax.swing.plaf.basic.BasicTextUI$RootView.modelToView(
	at javax.swing.plaf.basic.BasicTextUI.modelToView(
	at javax.swing.plaf.basic.BasicTextUI.modelToView(
	at javax.swing.text.JTextComponent.modelToView(
	at org.fife.ui.rtextarea.RTextAreaBase.possiblyUpdateCurrentLineHighlightLocation(
	at org.fife.ui.rtextarea.RTextArea.fireCaretUpdate(
	at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.fireCaretUpdate(
	at javax.swing.text.JTextComponent$
	at javax.swing.text.JTextComponent$MutableCaretEvent.stateChanged(
	at javax.swing.text.DefaultCaret.fireStateChanged(
	at javax.swing.text.DefaultCaret.changeCaretPosition(
	at javax.swing.text.DefaultCaret.handleSetDot(
	at javax.swing.text.DefaultCaret$DefaultFilterBypass.setDot(
	at javax.swing.text.NavigationFilter.setDot(
	at org.fife.ui.rtextarea.ConfigurableCaret$FoldAwareNavigationFilter.setDot(
	at javax.swing.text.DefaultCaret.setDot(
	at javax.swing.text.DefaultCaret.setDot(
	at javax.swing.text.JTextComponent.setCaretPosition(

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.


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.

(upload://cqhbdat3a5SL0Py8HCMp7ivYZNc.ino) (1.0 KB)

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