Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException: class com.sun.tools.javac.code.Type$ErrorType cannot be cast to class com.sun.tools.javac.code.Type$MethodType #4556

Open
tgeng opened this issue Aug 26, 2024 · 3 comments

Comments

@tgeng
Copy link

tgeng commented Aug 26, 2024

With Bazel 7.3.1 I am seeing build failing with the following error. I can't paste the source code here since that's confidential. But the line being reported is inside an enum declaration with dozens of enum value declarations. Specifically, line 219 is one enun declaration with some values from some method calls passed into the constructor. Please let me know if you need more details.

[2024-08-26T20:02:27.860Z] xxx/XXXX.java:219: error: An unhandled exception was thrown by the Error Prone static analysis plugin.

[2024-08-26T20:02:27.860Z]     destination_type(

[2024-08-26T20:02:27.860Z]                     ^

[2024-08-26T20:02:27.860Z]      Please report this at https://github.com/google/error-prone/issues/new and include the following:

[2024-08-26T20:02:27.860Z]   

[2024-08-26T20:02:27.860Z]      error-prone version: 2.23.0

[2024-08-26T20:02:27.860Z]      BugPattern: UnsafeWildcard

[2024-08-26T20:02:27.860Z]      Stack Trace:

[2024-08-26T20:02:27.860Z]      java.lang.ClassCastException: class com.sun.tools.javac.code.Type$ErrorType cannot be cast to class com.sun.tools.javac.code.Type$MethodType (com.sun.tools.javac.code.Type$ErrorType and com.sun.tools.javac.code.Type$MethodType are in module jdk.compiler of loader 'app')

[2024-08-26T20:02:27.860Z]   	at com.google.errorprone.bugpatterns.nullness.UnsafeWildcard.matchNewClass(UnsafeWildcard.java:179)

[2024-08-26T20:02:27.860Z]   	at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:449)

[2024-08-26T20:02:27.860Z]   	at com.google.errorprone.scanner.ErrorProneScanner.visitNewClass(ErrorProneScanner.java:773)

[2024-08-26T20:02:27.860Z]   	at com.google.errorprone.scanner.ErrorProneScanner.visitNewClass(ErrorProneScanner.java:150)

[2024-08-26T20:02:27.860Z]   	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1874)

[2024-08-26T20:02:27.860Z]   	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)

[2024-08-26T20:02:27.860Z]   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)

[2024-08-26T20:02:27.860Z]   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)

[2024-08-26T20:02:27.860Z]   	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:96)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreeScanner.visitVariable(TreeScanner.java:243)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.ErrorProneScanner.visitVariable(ErrorProneScanner.java:885)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.ErrorProneScanner.visitVariable(ErrorProneScanner.java:150)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1045)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:96)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:111)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:119)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:203)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:548)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:150)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:860)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:96)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:111)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:119)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:203)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:548)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:150)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:860)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:111)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:119)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:152)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:560)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:150)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:614)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:60)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:58)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.scanner.ErrorProneScannerTransformer.apply(ErrorProneScannerTransformer.java:43)

[2024-08-26T20:02:27.861Z]   	at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:156)

[2024-08-26T20:02:27.861Z]   	at com.google.devtools.build.buildjar.javac.plugins.errorprone.ErrorPronePlugin.postFlow(ErrorPronePlugin.java:122)

[2024-08-26T20:02:27.861Z]   	at com.google.devtools.build.buildjar.javac.BlazeJavaCompiler.flow(BlazeJavaCompiler.java:108)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1341)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:933)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)

[2024-08-26T20:02:27.861Z]   	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)

[2024-08-26T20:02:27.861Z]   	at com.google.devtools.build.buildjar.javac.BlazeJavacMain.compile(BlazeJavacMain.java:146)

[2024-08-26T20:02:27.861Z]   	at com.google.devtools.build.buildjar.ReducedClasspathJavaLibraryBuilder.fallback(ReducedClasspathJavaLibraryBuilder.java:105)

[2024-08-26T20:02:27.861Z]   	at com.google.devtools.build.buildjar.ReducedClasspathJavaLibraryBuilder.compileSources(ReducedClasspathJavaLibraryBuilder.java:67)

[2024-08-26T20:02:27.861Z]   	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.compileJavaLibrary(SimpleJavaLibraryBuilder.java:110)

[2024-08-26T20:02:27.861Z]   	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.run(SimpleJavaLibraryBuilder.java:118)

[2024-08-26T20:02:27.861Z]   	at com.google.devtools.build.buildjar.BazelJavaBuilder.build(BazelJavaBuilder.java:111)

[2024-08-26T20:02:27.861Z]   	at com.google.devtools.build.buildjar.BazelJavaBuilder.parseAndBuild(BazelJavaBuilder.java:91)

[2024-08-26T20:02:27.861Z]   	at com.google.devtools.build.buildjar.BazelJavaBuilder.lambda$main$0(BazelJavaBuilder.java:52)

[2024-08-26T20:02:27.861Z]   	at com.google.devtools.build.lib.worker.WorkRequestHandler$WorkRequestCallback.apply(WorkRequestHandler.java:252)

[2024-08-26T20:02:27.861Z]   	at com.google.devtools.build.lib.worker.WorkRequestHandler.respondToRequest(WorkRequestHandler.java:480)

[2024-08-26T20:02:27.861Z]   	at com.google.devtools.build.lib.worker.WorkRequestHandler.lambda$startResponseThread$1(WorkRequestHandler.java:433)

[2024-08-26T20:02:27.861Z]   	at java.base/java.lang.Thread.run(Thread.java:840)
@cushon
Copy link
Collaborator

cushon commented Aug 27, 2024

If you disable this check (with -Xep:UnsafeWildcard:OFF or @SuppressWarnings("UnsafeWildcard")), does the compilation succeed, or does a different error get reported?

@tgeng
Copy link
Author

tgeng commented Aug 27, 2024

Thanks for the quick reply! Actually it looks like the failure is flaky. It only happened once in our CI and the same Bazel target was able to build later.
I also tried checking out the same commit locally and build it and that worked too.

@cushon
Copy link
Collaborator

cushon commented Sep 10, 2024

Interesting, thanks for following up! I'm going to close this out, but please let us know if you see it again or it starts reproducing consistently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants
@cushon @tgeng and others