Open TysonMN opened 1 year ago
This exception stopped happening when I upgraded the version of IntelliJ from 2022.3 to 2023.1. Specifically, in my build.gradle
file, I changed
intellij {
version = "2023.1"
plugins = ["PsiViewer:231-SNAPSHOT", "com.intellij.java"]
}
to
intellij {
version = "2022.3"
plugins = ["PsiViewer:223-SNAPSHOT", "com.intellij.java"]
}
Same problem on IC233
2023-10-26 20:41:10,558 [ 42461] SEVERE - #c.i.o.a.i.ActionUpdater - IntelliJ IDEA 2023.3 EAP Build #IC-233.10527.20
2023-10-26 20:41:10,558 [ 42461] SEVERE - #c.i.o.a.i.ActionUpdater - JDK: 17.0.8.1; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o.
2023-10-26 20:41:10,558 [ 42461] SEVERE - #c.i.o.a.i.ActionUpdater - OS: Windows 11
2023-10-26 20:41:10,558 [ 42461] SEVERE - #c.i.o.a.i.ActionUpdater - Last Action: ShowSettings
Hi, and sorry for the late reply. I believe this error can happen when an ANTLRLexerAdaptor
is instantiated automatically by the IDE before the plugin is finished loading. In your case, it's even possible that the buildSearchableOptions
task doesn't load your plugin at all, otherwise your custom ParserDefinition
would have called PSIElementTypeFactory.defineLanguageIElementTypes()
and tokenElementTypes
wouldn't be null.
We had a similar problem in the StringTemplate 4 plugin, and a contributor ended up using a lazy value to ensure the initialization is done even when the ParserDefinition
is not instantiated.
However, I think the problem could also be fixed by creating your ANTLRLexerAdaptor
s in a single place, for example a static factory method:
class AntlrLexerFactory {
static {
PSIElementTypeFactory.defineLanguageIElementTypes(
YourLanguage.INSTANCE,
YourLexer.tokenNames,
YourParser.ruleNames
);
}
public static ANTLRLexerAdaptor createLexer(Lexer lexer) {
return new ANTLRLexerAdaptor(YourLanguage.INSTANCE, lexer);
}
}
This way, the static block will ensure a proper initialization before a lexer is created. Then you can remove this initialization from your ParserDefinition
's constructor.
When building my plugin, there is a
NullPointerException
in the ANTLR adaptor. It seems benign because the build continues, is eventually successful, and the built plugin works correctly.Steps to reproduce
buildPlugin
(actually, it should suffice to execute the gradle taskbuildSearchableOptions
)Expected behavior
Build completes successfully and without any errors
Actual behavior
Build completes successfully but with one error due to the following
NullPointerException
:Suggested fix
I think the fix is rather straight forward. Here is the code in question:
https://github.com/antlr/antlr4-intellij-adaptor/blob/e002d4d7cadb9f3a0a5db9202fed8533417b8cf5/src/main/java/org/antlr/intellij/adaptor/lexer/ANTLRLexerAdaptor.java#L56
https://github.com/antlr/antlr4-intellij-adaptor/blob/e002d4d7cadb9f3a0a5db9202fed8533417b8cf5/src/main/java/org/antlr/intellij/adaptor/lexer/ANTLRLexerAdaptor.java#L132
https://github.com/antlr/antlr4-intellij-adaptor/blob/e002d4d7cadb9f3a0a5db9202fed8533417b8cf5/src/main/java/org/antlr/intellij/adaptor/lexer/ANTLRLexerAdaptor.java#L181-L189
If
tokenElementTypes
isnull
(on line 188), then I think this method should returnnull
. I had a similar problem in my code, and returningnull
in this case seems to have fixed the problem.Other
For the record, this happens with the
0.1
release, which is currently the only release.