antlr / intellij-plugin-v4

An IntelliJ plugin for ANTLR v4
https://plugins.jetbrains.com/plugin/7358-antlr-v4
BSD 3-Clause "New" or "Revised" License
462 stars 103 forks source link

ANTLR v4 1.20 - java.lang.Throwable: Read access is allowed from inside read-action (or EDT) only (see com.intellij.openapi.application.Application.runReadAction()) #631

Closed LucasHenrique-dev closed 12 months ago

LucasHenrique-dev commented 1 year ago

I'm using ANTLR v4 1.20

This error triggered when I clicked "Generate ANTLR Recognizer"

image image

ANTLR Configure

image

Stack Trace

java.lang.Throwable: Read access is allowed from inside read-action (or EDT) only (see com.intellij.openapi.application.Application.runReadAction())
Current thread: Thread[ApplicationImpl pooled thread 124,4,main] 937709905 (EventQueue.isDispatchThread()=false)
SystemEventQueueThread: Thread[AWT-EventQueue-0,6,main] 765331596
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:202)
    at com.intellij.openapi.application.impl.ApplicationImpl.assertReadAccessAllowed(ApplicationImpl.java:1004)
    at com.intellij.openapi.roots.impl.DirectoryIndexImpl.checkAvailability(DirectoryIndexImpl.java:250)
    at com.intellij.openapi.roots.impl.DirectoryIndexImpl.getPackageName(DirectoryIndexImpl.java:213)
    at com.intellij.openapi.roots.impl.ProjectFileIndexImpl.getPackageNameByDirectory(ProjectFileIndexImpl.java:250)
    at org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile.getANTLRArgs(RunANTLROnGrammarFile.java:197)
    at org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile.getANTLRArgsAsList(RunANTLROnGrammarFile.java:178)
    at org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile.antlr(RunANTLROnGrammarFile.java:131)
    at org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile.run(RunANTLROnGrammarFile.java:78)
    at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:429)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:114)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressSynchronously$9(CoreProgressManager.java:513)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$new$0(ProgressRunner.java:84)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:252)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:186)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:604)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:679)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:635)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:603)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:173)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:252)
    at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
    at java.base/java.lang.Thread.run(Thread.java:833)

Induced

Following exceptions happened soon after this one, most probably they are induced.

2023-04-02T20:34:20.010
java.lang.Throwable: Read access is allowed from inside read-action (or EDT) only (see com.intellij.openapi.application.Application.runReadAction())
Current thread: Thread[ApplicationImpl pooled thread 124,4,main] 937709905 (EventQueue.isDispatchThread()=false)
SystemEventQueueThread: Thread[AWT-EventQueue-0,6,main] 765331596
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:202)
    at com.intellij.openapi.application.impl.ApplicationImpl.assertReadAccessAllowed(ApplicationImpl.java:1004)
    at com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexDataImpl.ensureIsUpToDate(WorkspaceFileIndexDataImpl.kt:127)
    at com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexDataImpl.getFileInfo(WorkspaceFileIndexDataImpl.kt:70)
    at com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexDataImpl.getPackageName(WorkspaceFileIndexDataImpl.kt:279)
    at com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexImpl.getPackageName(WorkspaceFileIndexImpl.kt:228)
    at com.intellij.openapi.roots.impl.DirectoryIndexImpl.getPackageName(DirectoryIndexImpl.java:215)
    at com.intellij.openapi.roots.impl.ProjectFileIndexImpl.getPackageNameByDirectory(ProjectFileIndexImpl.java:250)
    at org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile.getANTLRArgs(RunANTLROnGrammarFile.java:197)
    at org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile.getANTLRArgsAsList(RunANTLROnGrammarFile.java:178)
    at org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile.antlr(RunANTLROnGrammarFile.java:131)
    at org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile.run(RunANTLROnGrammarFile.java:78)
    at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:429)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:114)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressSynchronously$9(CoreProgressManager.java:513)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$new$0(ProgressRunner.java:84)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:252)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:186)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:604)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:679)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:635)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:603)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:173)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:252)
    at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
    at java.base/java.lang.Thread.run(Thread.java:833)

2023-04-02T20:34:20.010
java.lang.Throwable: Read access is allowed from inside read-action (or EDT) only (see com.intellij.openapi.application.Application.runReadAction())
Current thread: Thread[ApplicationImpl pooled thread 124,4,main] 937709905 (EventQueue.isDispatchThread()=false)
SystemEventQueueThread: Thread[AWT-EventQueue-0,6,main] 765331596
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:202)
    at com.intellij.openapi.application.impl.ApplicationImpl.assertReadAccessAllowed(ApplicationImpl.java:1004)
    at com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexDataImpl.ensureIsUpToDate(WorkspaceFileIndexDataImpl.kt:127)
    at com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexDataImpl.getFileInfo(WorkspaceFileIndexDataImpl.kt:70)
    at com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexImpl.getFileInfo(WorkspaceFileIndexImpl.kt:220)
    at com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexImpl.findFileSetWithCustomData(WorkspaceFileIndexImpl.kt:205)
    at com.intellij.openapi.roots.impl.ProjectFileIndexImpl.getContentRootForFile(ProjectFileIndexImpl.java:219)
    at com.intellij.openapi.roots.impl.ProjectFileIndexImpl.getContentRootForFile(ProjectFileIndexImpl.java:213)
    at org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile.getContentRoot(RunANTLROnGrammarFile.java:269)
    at org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile.getANTLRArgs(RunANTLROnGrammarFile.java:209)
    at org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile.getANTLRArgsAsList(RunANTLROnGrammarFile.java:178)
    at org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile.antlr(RunANTLROnGrammarFile.java:131)
    at org.antlr.intellij.plugin.parsing.RunANTLROnGrammarFile.run(RunANTLROnGrammarFile.java:78)
    at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:429)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:114)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressSynchronously$9(CoreProgressManager.java:513)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$new$0(ProgressRunner.java:84)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:252)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:186)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:604)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:679)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:635)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:603)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:173)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:252)
    at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
    at java.base/java.lang.Thread.run(Thread.java:833)

Grammar *.g4 file

grammar GeradorRelatorio;

//SÍMBOLOS TERMINAIS
NUM: [0-9]+;
STRING: ["][a-zA-Z0-9 \\/:._]+["];

ESPACO: [ \t\n\r]+ -> skip ;

//SÍMBOLOS NÃO TERMINAIS
program
    : exp+ EOF
    ;

exp
    : 'getTopEmpresasMaisContratam' '(' NUM ')'
    | 'extrairDados' '(' STRING ')'
    | 'estagiosPorCurso' '(' STRING ')'
    ;

I can visualize the Parse tree, by the way

image

It also seems to create the files correctly

image

This is my first time using it, is there something that I should do or is this expected?

elisaado commented 1 year ago

Same here, anything that helps?

ThatcherChen commented 1 year ago

I have the same problem.

adminers commented 1 year ago

me to

alchitry commented 1 year ago

For anyone looking for a fix now, you can do the following.

  1. Clone my fork with the fix https://github.com/alchitry/intellij-plugin-v4/tree/read-access-fix
  2. Open it in Intllij
  3. If you get an error saying
    A problem occurred configuring root project 'intellij-plugin-v4'.
    > Could not resolve all files for configuration ':classpath'.
    > Could not resolve org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.13.3.
    ...

    Then open Settings->Build, Execution, Development->Build Tools->Gradle and set the Gradle JVM to 11. Resync gradle and you should be good.

  4. Open the gradle tasks section (mine is on the right side as the little gradle elephant) and run the build task.
  5. Then go to Settings->Plugins and click the gear icon. Choose "Install Plugin from Disk" then navigate to where you cloned the project -> build -> distributions and point it to the .zip in there.
  6. Restart Intellij and you should be using the fixed version.
cnscottluo commented 1 year ago

For anyone looking for a fix now, you can do the following.

  1. Clone my fork with the fix alchitry/intellij-plugin-v4@read-access-fix
  2. Open it in Intllij
  3. If you get an error saying
A problem occurred configuring root project 'intellij-plugin-v4'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.13.3.
   ...

Then open Settings->Build, Execution, Development->Build Tools->Gradle and set the Gradle JVM to 11. Resync gradle and you should be good. 4. Open the gradle tasks section (mine is on the right side as the little gradle elephant) and run the build task. 5. Then go to Settings->Plugins and click the gear icon. Choose "Install Plugin from Disk" then navigate to where you cloned the project -> build -> distributions and point it to the .zip in there. 6. Restart Intellij and you should be using the fixed version.

it's not work for me

alchitry commented 1 year ago

What part isn't working?

bseib commented 1 year ago

For anyone looking for a fix now, you can do the following.

1. Clone my fork with the fix https://github.com/alchitry/intellij-plugin-v4/tree/read-access-fix

@alchitry would you open a PR with your fix?

alchitry commented 1 year ago

I had one (https://github.com/antlr/intellij-plugin-v4/pull/639) but it was closed by a different fix.

bseib commented 1 year ago

I had one (#639) but it was closed by a different fix.

Ah, thanks. I see that @bjansen had that fix in a milestone named 1.21, which is now 100% complete (but that milestone is still open). So I will assume a new plugin release could happen soon-ish.

I suppose this issue should be closed now too.

whisper-bye commented 1 year ago

Same problem. Is there any progress? When will the new version be released?

bjansen commented 12 months ago

This was fixed in 1.21 which was released yesterday, sorry for the delay 😬