-
Bug
-
Resolution: Fixed
-
P3
-
16, 17, 18
A DESCRIPTION OF THE PROBLEM :
jshell crashes with an InternalError when an explicit import for `java.lang.annotation.Repeatable` is used followed by a usage of `@Repeatable` with a not yet declared container annotation class.
Without the explicit import for `java.lang.annotation.Repeatable` no crash occurs.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Open jshell
2. Copy the code provided below and execute it (either each line one by one, or all at once)
ACTUAL -
jshell crashes (stack trace for JDK 18-ea+3-63):
Exception in thread "main" java.lang.InternalError: Exception during analyze - java.lang.ClassCastException: class com.sun.tools.javac.code.Attribute$UnresolvedClass cannot be cast to class com.sun.tools.javac.code.Attribute$Class (com.sun.tools.javac.code.Attribute$UnresolvedClass and com.sun.tools.javac.code.Attribute$Class are in module jdk.compiler of loader 'app')
at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.analyze(TaskFactory.java:393)
at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.<init>(TaskFactory.java:384)
at jdk.jshell/jdk.jshell.TaskFactory.lambda$analyze$1(TaskFactory.java:177)
at jdk.jshell/jdk.jshell.TaskFactory.lambda$runTask$4(TaskFactory.java:212)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskPool.getTask(JavacTaskPool.java:193)
at jdk.jshell/jdk.jshell.TaskFactory.runTask(TaskFactory.java:205)
at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:174)
at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:160)
at jdk.jshell/jdk.jshell.Eval.compileAndLoad(Eval.java:1010)
at jdk.jshell/jdk.jshell.Eval.declare(Eval.java:890)
at jdk.jshell/jdk.jshell.Eval.eval(Eval.java:137)
at jdk.jshell/jdk.jshell.JShell.eval(JShell.java:493)
at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSource(JShellTool.java:3618)
at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSourceCatchingReset(JShellTool.java:1342)
at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processInput(JShellTool.java:1240)
at jdk.jshell/jdk.internal.jshell.tool.JShellTool.run(JShellTool.java:1211)
at jdk.jshell/jdk.internal.jshell.tool.JShellTool.start(JShellTool.java:995)
at jdk.jshell/jdk.internal.jshell.tool.JShellToolBuilder.start(JShellToolBuilder.java:261)
at jdk.jshell/jdk.internal.jshell.tool.JShellToolProvider.main(JShellToolProvider.java:120)
Caused by: java.lang.IllegalStateException: java.lang.ClassCastException: class com.sun.tools.javac.code.Attribute$UnresolvedClass cannot be cast to class com.sun.tools.javac.code.Attribute$Class (com.sun.tools.javac.code.Attribute$UnresolvedClass and com.sun.tools.javac.code.Attribute$Class are in module jdk.compiler of loader 'app')
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:383)
at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.analyze(TaskFactory.java:390)
... 18 more
Caused by: java.lang.ClassCastException: class com.sun.tools.javac.code.Attribute$UnresolvedClass cannot be cast to class com.sun.tools.javac.code.Attribute$Class (com.sun.tools.javac.code.Attribute$UnresolvedClass and com.sun.tools.javac.code.Attribute$Class are in module jdk.compiler of loader 'app')
at jdk.compiler/com.sun.tools.javac.comp.Check.validateRepeatable(Check.java:3102)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5442)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5369)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5200)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitClassDef(Attr.java:971)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:819)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:668)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:742)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5478)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5369)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5200)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5145)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1317)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1290)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:404)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$analyze$1(JavacTaskImpl.java:379)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:379)
... 19 more
---------- BEGIN SOURCE ----------
import java.lang.annotation.Repeatable;
@Repeatable(FooContainer.class)
@interface Foo { int value(); }
---------- END SOURCE ----------
jshell crashes with an InternalError when an explicit import for `java.lang.annotation.Repeatable` is used followed by a usage of `@Repeatable` with a not yet declared container annotation class.
Without the explicit import for `java.lang.annotation.Repeatable` no crash occurs.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Open jshell
2. Copy the code provided below and execute it (either each line one by one, or all at once)
ACTUAL -
jshell crashes (stack trace for JDK 18-ea+3-63):
Exception in thread "main" java.lang.InternalError: Exception during analyze - java.lang.ClassCastException: class com.sun.tools.javac.code.Attribute$UnresolvedClass cannot be cast to class com.sun.tools.javac.code.Attribute$Class (com.sun.tools.javac.code.Attribute$UnresolvedClass and com.sun.tools.javac.code.Attribute$Class are in module jdk.compiler of loader 'app')
at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.analyze(TaskFactory.java:393)
at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.<init>(TaskFactory.java:384)
at jdk.jshell/jdk.jshell.TaskFactory.lambda$analyze$1(TaskFactory.java:177)
at jdk.jshell/jdk.jshell.TaskFactory.lambda$runTask$4(TaskFactory.java:212)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskPool.getTask(JavacTaskPool.java:193)
at jdk.jshell/jdk.jshell.TaskFactory.runTask(TaskFactory.java:205)
at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:174)
at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:160)
at jdk.jshell/jdk.jshell.Eval.compileAndLoad(Eval.java:1010)
at jdk.jshell/jdk.jshell.Eval.declare(Eval.java:890)
at jdk.jshell/jdk.jshell.Eval.eval(Eval.java:137)
at jdk.jshell/jdk.jshell.JShell.eval(JShell.java:493)
at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSource(JShellTool.java:3618)
at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSourceCatchingReset(JShellTool.java:1342)
at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processInput(JShellTool.java:1240)
at jdk.jshell/jdk.internal.jshell.tool.JShellTool.run(JShellTool.java:1211)
at jdk.jshell/jdk.internal.jshell.tool.JShellTool.start(JShellTool.java:995)
at jdk.jshell/jdk.internal.jshell.tool.JShellToolBuilder.start(JShellToolBuilder.java:261)
at jdk.jshell/jdk.internal.jshell.tool.JShellToolProvider.main(JShellToolProvider.java:120)
Caused by: java.lang.IllegalStateException: java.lang.ClassCastException: class com.sun.tools.javac.code.Attribute$UnresolvedClass cannot be cast to class com.sun.tools.javac.code.Attribute$Class (com.sun.tools.javac.code.Attribute$UnresolvedClass and com.sun.tools.javac.code.Attribute$Class are in module jdk.compiler of loader 'app')
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:383)
at jdk.jshell/jdk.jshell.TaskFactory$AnalyzeTask.analyze(TaskFactory.java:390)
... 18 more
Caused by: java.lang.ClassCastException: class com.sun.tools.javac.code.Attribute$UnresolvedClass cannot be cast to class com.sun.tools.javac.code.Attribute$Class (com.sun.tools.javac.code.Attribute$UnresolvedClass and com.sun.tools.javac.code.Attribute$Class are in module jdk.compiler of loader 'app')
at jdk.compiler/com.sun.tools.javac.comp.Check.validateRepeatable(Check.java:3102)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5442)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5369)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5200)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitClassDef(Attr.java:971)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:819)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:668)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:742)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5478)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5369)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5200)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5145)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1317)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1290)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:404)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$analyze$1(JavacTaskImpl.java:379)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:379)
... 19 more
---------- BEGIN SOURCE ----------
import java.lang.annotation.Repeatable;
@Repeatable(FooContainer.class)
@interface Foo { int value(); }
---------- END SOURCE ----------
- relates to
-
JDK-8250217 com.sun.tools.javac.api.JavacTaskImpl swallows compiler exceptions potentially producing false positive test results
-
- Resolved
-