intellij-plugin-v4 icon indicating copy to clipboard operation
intellij-plugin-v4 copied to clipboard

NPE with IntelliJ 2022.1.1

Open electrum opened this issue 2 years ago • 7 comments

I had recently opened the IDE and hadn't opened any language files. This happened while the IDE was idle.

java.lang.NullPointerException
	at org.antlr.intellij.plugin.parsing.ParsingUtils.parseText(ParsingUtils.java:206)
	at org.antlr.intellij.plugin.ANTLRv4PluginController.lambda$parseText$3(ANTLRv4PluginController.java:448)
	at com.intellij.openapi.progress.util.BackgroundTaskUtil.lambda$computeInBackgroundAndTryWait$6(BackgroundTaskUtil.java:171)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:189)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:608)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:683)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:639)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:607)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:176)
	at com.intellij.openapi.progress.util.BackgroundTaskUtil.lambda$computeInBackgroundAndTryWait$7(BackgroundTaskUtil.java:170)
	at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:295)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
	at java.base/java.lang.Thread.run(Thread.java:829)

electrum avatar May 25 '22 23:05 electrum

Wow! Latest version 1.19.2?

parrt avatar May 26 '22 00:05 parrt

IntelliJ said all plugins were up to date. I’ll manually confirm the plugin version next time I’m at the office.

electrum avatar May 26 '22 05:05 electrum

Ok, thanks. So literally there were no .g4 files open the last time you had intellij open? I think it is executing code that can only happen when there's a grammar file. It looks to me like we are passing in a null lexer (lg):

previewState.parsingResult = ParsingUtils.parseText(
	previewState.g, previewState.lg, previewState.startRuleName,
	grammarFile, inputText, project
);

which then tries to parse:

lexEngine = lg.createLexerInterpreter(input);

This does seem to be an unprotected "missing or bad lexer" situation but I'm wondering why it doesn't come up before. Maybe you could find the log file in the help menu and attach it here or email it to me?

parrt avatar May 27 '22 19:05 parrt

I get the same stacktrace:

java.lang.NullPointerException
	at org.antlr.intellij.plugin.parsing.ParsingUtils.parseText(ParsingUtils.java:206)
	at org.antlr.intellij.plugin.ANTLRv4PluginController.lambda$parseText$3(ANTLRv4PluginController.java:448)
	at com.intellij.openapi.progress.util.BackgroundTaskUtil.lambda$computeInBackgroundAndTryWait$6(BackgroundTaskUtil.java:171)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:189)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:608)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:683)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:639)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:607)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:176)
	at com.intellij.openapi.progress.util.BackgroundTaskUtil.lambda$computeInBackgroundAndTryWait$7(BackgroundTaskUtil.java:170)
	at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:295)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
	at java.base/java.lang.Thread.run(Thread.java:829)

It happened shortly after I closed the .g4 file.

kspalaiologos avatar Jun 22 '22 14:06 kspalaiologos

Is there a specific process you could identify that causes it fairly reliable? Another words can you start up your IDE, Open that file then close it and get the error? Thanks very much for Stack trace! Could you post your grammar as well if it's not private? Happy to get log files too.

parrt avatar Jun 24 '22 21:06 parrt

For me this happened with https://github.com/trinodb/trino

electrum avatar Jun 25 '22 02:06 electrum

Seen with 2022.1.3 and all plugins up to date as well. Not quite sure, if there was a g4 file open or not. Just started IJ with a project opened and closed a bunch of files, then saw the event log entry with this same back trace, Still drilling down a bit...

ktr62 avatar Jul 07 '22 07:07 ktr62

The preview input is now parsed in a background thread, so it's theoretically possible to close the editor before the scheduled bg thread is executed. In this case, editorFileClosedEvent will clear both previewState.g and previewState.lg, causing a NPE in the bg thread.

bjansen avatar Mar 29 '23 18:03 bjansen