jshiell / checkstyle-idea

CheckStyle plug-in for IntelliJ IDEA
https://plugins.jetbrains.com/plugin/1065-checkstyle-idea
Other
885 stars 160 forks source link

java.lang.ClassCastException: antlr.CommonHiddenStreamToken cannot be cast to antlr.Token #449

Closed MCMicS closed 6 months ago

MCMicS commented 5 years ago

With the last updates of Idea and the plugin I get following error. If I press reload config it work for an short time but then it appears again. OS: Windows IDEA: 2019.1.3

org.infernus.idea.checkstyle.exception.CheckstyleToolException: Exception was thrown while processing Foo.java
    at org.infernus.idea.checkstyle.service.CheckstyleActionsImpl.executeCommand(CheckstyleActionsImpl.java:136)
    at org.infernus.idea.checkstyle.service.CheckstyleActionsImpl.scan(CheckstyleActionsImpl.java:76)
    at org.infernus.idea.checkstyle.checker.CheckStyleChecker.scan(CheckStyleChecker.java:45)
    at org.infernus.idea.checkstyle.checker.ScanFiles.lambda$checkFiles$6(ScanFiles.java:190)
    at java.util.Optional.map(Optional.java:215)
    at org.infernus.idea.checkstyle.checker.ScanFiles.checkFiles(ScanFiles.java:190)
    at org.infernus.idea.checkstyle.checker.ScanFiles.processFilesForModuleInfoAndScan(ScanFiles.java:149)
    at org.infernus.idea.checkstyle.checker.ScanFiles.call(ScanFiles.java:75)
    at org.infernus.idea.checkstyle.checker.ScanFiles.call(ScanFiles.java:31)
    at com.intellij.openapi.application.impl.ApplicationImpl$2.call(ApplicationImpl.java:339)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing Foo.java
    at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:307)
    at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:220)
    at org.infernus.idea.checkstyle.service.cmd.OpScan.processAndAudit(OpScan.java:76)
    at org.infernus.idea.checkstyle.service.cmd.OpScan.execute(OpScan.java:52)
    at org.infernus.idea.checkstyle.service.cmd.OpScan.execute(OpScan.java:22)
    at org.infernus.idea.checkstyle.service.CheckstyleActionsImpl.executeCommand(CheckstyleActionsImpl.java:130)
    ... 13 more
Caused by: java.lang.ClassCastException: antlr.CommonHiddenStreamToken cannot be cast to antlr.Token
    at antlr.CharScanner.makeToken(CharScanner.java:173)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaLexer.mBLOCK_COMMENT_CONTENT(GeneratedJavaLexer.java:1258)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaLexer.mBLOCK_COMMENT_BEGIN(GeneratedJavaLexer.java:1199)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaLexer.nextToken(GeneratedJavaLexer.java:335)
    at antlr.TokenStreamHiddenTokenFilter.consume(TokenStreamHiddenTokenFilter.java:38)
    at antlr.TokenStreamHiddenTokenFilter.consumeFirst(TokenStreamHiddenTokenFilter.java:42)
    at antlr.TokenStreamHiddenTokenFilter.nextToken(TokenStreamHiddenTokenFilter.java:122)
    at antlr.TokenBuffer.fill(TokenBuffer.java:69)
    at antlr.TokenBuffer.LA(TokenBuffer.java:80)
    at antlr.LLkParser.LA(LLkParser.java:52)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.compilationUnit(GeneratedJavaRecognizer.java:158)
    at com.puppycrawl.tools.checkstyle.JavaParser.parse(JavaParser.java:97)
    at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:160)
    at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:85)
    at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:332)
    at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:294)
    ... 18 more
MCMicS commented 4 years ago

Got the exception again (checkstyle 8.26). This was happen from the svn commit dialog with enabled checkstyle check before commit. I've got an dialog that there was checkstyle error (can choose between Review, Cancel or Commit). After click on Commit I saw the error in Event Log

I have an screenshot of the balloon: Stacktrace error

Root cause:
class antlr.CommonHiddenStreamToken cannot be cast to class antlr.Token (antlr.CommonHiddenStreamToken is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @423461cf; antlr.Token is in unnamed module of loader org.infernus.idea.checkstyle.util.ChildFirstURLClassLoader @62f20787)
java.lang.ClassCastException: class antlr.CommonHiddenStreamToken cannot be cast to class antlr.Token (antlr.CommonHiddenStreamToken is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @423461cf; antlr.Token is in unnamed module of loader org.infernus.idea.checkstyle.util.ChildFirstURLClassLoader @62f20787)
  at antlr.CharScanner.makeToken(CharScanner.java:173)
  at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaLexer.mIDENT(GeneratedJavaLexer.java:1743)
  at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaLexer.nextToken(GeneratedJavaLexer.java:391)
  at antlr.TokenStreamHiddenTokenFilter.consume(TokenStreamHiddenTokenFilter.java:38)
  at antlr.TokenStreamHiddenTokenFilter.consumeFirst(TokenStreamHiddenTokenFilter.java:42)
  at antlr.TokenStreamHiddenTokenFilter.nextToken(TokenStreamHiddenTokenFilter.java:122)
  at antlr.TokenBuffer.fill(TokenBuffer.java:69)
  at antlr.TokenBuffer.LA(TokenBuffer.java:80)
  at antlr.LLkParser.LA(LLkParser.java:52)
  at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.compilationUnit(GeneratedJavaRecognizer.java:158)
  at com.puppycrawl.tools.checkstyle.JavaParser.parse(JavaParser.java:99)
  at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:159)
  at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:85)
  at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:328)
  at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:290)
  at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:216)
  at org.infernus.idea.checkstyle.service.cmd.OpScan.processAndAudit(OpScan.java:76)
  at org.infernus.idea.checkstyle.service.cmd.OpScan.execute(OpScan.java:52)
  at org.infernus.idea.checkstyle.service.cmd.OpScan.execute(OpScan.java:22)
  at org.infernus.idea.checkstyle.service.CheckstyleActionsImpl.executeCommand(CheckstyleActionsImpl.java:130)
  at org.infernus.idea.checkstyle.service.CheckstyleActionsImpl.scan(CheckstyleActionsImpl.java:76)
  at org.infernus.idea.checkstyle.checker.CheckStyleChecker.scan(CheckStyleChecker.java:45)
  at org.infernus.idea.checkstyle.checker.ScanFiles.lambda$checkFiles$7(ScanFiles.java:197)
  at java.base/java.util.Optional.map(Optional.java:265)
  at org.infernus.idea.checkstyle.checker.ScanFiles.checkFiles(ScanFiles.java:197)
  at org.infernus.idea.checkstyle.checker.ScanFiles.processFilesForModuleInfoAndScan(ScanFiles.java:156)
  at org.infernus.idea.checkstyle.checker.ScanFiles.call(ScanFiles.java:78)
  at org.infernus.idea.checkstyle.checker.ScanFiles.call(ScanFiles.java:32)
  at com.intellij.openapi.application.impl.ApplicationImpl$2.call(ApplicationImpl.java:322)
  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.lang.Thread.run(Thread.java:834)

IntelliJ IDEA 2019.2.4 (Ultimate Edition) Build #IU-192.7142.36, built on October 29, 2019

jshiell commented 4 years ago

Thank you!

MCMicS commented 4 years ago

You're welcome. Hope it helps to identify the checkstyle error

jshiell commented 4 years ago

Right, I remain clueless. So, I've added some debug to this one. If you enable debug on the appropriate path (Help -> Debug Log Settings..., and add #org.infernus.idea.checkstyle.checker.CheckStyleChecker) then the IDEA log (Help -> Show Log in Finder) should print a debug statement whenever we create a new Checker, e.g.

2019-11-28 17:06:51,333 [ 128830]  DEBUG - tyle.checker.CheckStyleChecker - Creating Checkstyle instances with CheckStyle classpath:
URLClassLoader: org.infernus.idea.checkstyle.util.ChildFirstURLClassLoader
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/classes/
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/checkstyle-8.25.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/picocli-4.0.4.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/antlr-2.7.7.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/antlr4-runtime-4.7.2.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/commons-beanutils-1.9.4.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/guava-28.1-jre.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/Saxon-HE-9.9.1-5.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/commons-collections-3.2.2.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/failureaccess-1.0.1.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/jsr305-3.0.2.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/checker-qual-2.8.1.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/error_prone_annotations-2.3.2.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/j2objc-annotations-1.3.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/checkstyle/lib/animal-sniffer-annotations-1.18.jar
- url=file:/Users/jshiell/Projects/checkstyle-idea/test-configs/cp-test.jar
UrlClassLoader: com.intellij.ide.plugins.cl.PluginClassLoader
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/lib/slf4j-log4j12-1.7.25.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/lib/slf4j-api-1.7.25.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/lib/log4j-1.2.17.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/lib/checkstyle-idea-5.34.0.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/lib/jcl-over-slf4j-1.7.25.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/lib/commons-codec-1.11.jar
- url=file:/Users/jshiell/Library/Application%20Support/IntelliJIdea2019.2/CheckStyle-IDEA/lib/commons-io-2.6.jar

If you're able to capture the state of this when it's in an error state then hopefully that will shed some light on what's going on.

CheckStyle-IDEA-5.34.0-debug

MCMicS commented 4 years ago

I will enable it tomorrow

MCMicS commented 4 years ago

Hi. Today at 9:22 the error occurs again two times. Then I clicked Build and the error is gone.

The log is attached checkstyle-idea_Crash.log

jshiell commented 4 years ago

Thanks! I'm off next week, so will take another stab at it 🤞

MCMicS commented 4 years ago

thanks. I had a short look on the log output but found no difference between both calls

jshiell commented 4 years ago

I, unfortunately, concur. I see no difference between these that could lead to this sort of problem. And the whole point of the child-first classloader is to avoid the chance of hitting nasties further down the chain.

I fear there's something important that I'm missing here - class path problems should generally be pretty deterministic. It's not like we're changing the JARs accessible to the classpath unless we change the Checkstyle version. I'll keep thinking.

jshiell commented 6 months ago

Closed due to no further updates, and that by now we're dealing with meaninfully different components.