-
Bug
-
Resolution: Fixed
-
P3
-
None
-
b11
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8342159 | 23.0.2 | Liam Miller-Cushon | P3 | Resolved | Fixed | b03 |
The following example shows a crash in javac while attaching type annotations read from a class file.
To locate type annotations on class types, javac uses getEnclosingType() to look up enclosing types to interpret type_path_kind=1 entries. The location on inner classes is expressed 'backwards', where an empty path locates the on the 'outermost part of the type for which a type annotation is admissible', and each type_path_kind=1 steps into a nested type.
For this specific issue, there is enough information in the InnerClasses attribute to determine whether the class type has an enclosing type, so this symbol completion could likely be avoided for classes without an enclosing type.
In general, completion failures in this code should not trigger a crash. There are a few possible options: report a non-crash error, report a warning (which could be configurable with -Xlint:classfile or another option), or try to silently tolerate the missing information.
=== ./B.java
import static java.lang.annotation.ElementType.TYPE_USE;
import java.lang.annotation.Target;
class B {
private @Anno A<String> a;
@Target(TYPE_USE)
@interface Anno {}
}
=== ./C.java
class C {
B b;
}
=== ./A.java
class A<E> {}
$ javac -fullversion
javac full version "24-ea+9-972"
$ javac A.java B.java C.java
$ rm A.clas
$ javac C.java -sourcepath : -XDdev
An exception has occurred in the compiler (24-ea). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for A not found
at jdk.compiler/com.sun.tools.javac.code.ClassFinder.newCompletionFailure(ClassFinder.java:420)
at jdk.compiler/com.sun.tools.javac.code.ClassFinder.classFileNotFound(ClassFinder.java:407)
at jdk.compiler/com.sun.tools.javac.code.ClassFinder.fillIn(ClassFinder.java:402)
at jdk.compiler/com.sun.tools.javac.code.ClassFinder.complete(ClassFinder.java:302)
at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:703)
at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1471)
at jdk.compiler/com.sun.tools.javac.code.Symbol.apiComplete(Symbol.java:709)
at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$1.getEnclosingType(ClassReader.java:612)
at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationLocator.visitClassType(ClassReader.java:2525)
at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationLocator.visitClassType(ClassReader.java:2501)
at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:1053)
at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4920)
at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationSymbolVisitor.addTypeAnnotations(ClassReader.java:2466)
To locate type annotations on class types, javac uses getEnclosingType() to look up enclosing types to interpret type_path_kind=1 entries. The location on inner classes is expressed 'backwards', where an empty path locates the on the 'outermost part of the type for which a type annotation is admissible', and each type_path_kind=1 steps into a nested type.
For this specific issue, there is enough information in the InnerClasses attribute to determine whether the class type has an enclosing type, so this symbol completion could likely be avoided for classes without an enclosing type.
In general, completion failures in this code should not trigger a crash. There are a few possible options: report a non-crash error, report a warning (which could be configurable with -Xlint:classfile or another option), or try to silently tolerate the missing information.
=== ./B.java
import static java.lang.annotation.ElementType.TYPE_USE;
import java.lang.annotation.Target;
class B {
private @Anno A<String> a;
@Target(TYPE_USE)
@interface Anno {}
}
=== ./C.java
class C {
B b;
}
=== ./A.java
class A<E> {}
$ javac -fullversion
javac full version "24-ea+9-972"
$ javac A.java B.java C.java
$ rm A.clas
$ javac C.java -sourcepath : -XDdev
An exception has occurred in the compiler (24-ea). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for A not found
at jdk.compiler/com.sun.tools.javac.code.ClassFinder.newCompletionFailure(ClassFinder.java:420)
at jdk.compiler/com.sun.tools.javac.code.ClassFinder.classFileNotFound(ClassFinder.java:407)
at jdk.compiler/com.sun.tools.javac.code.ClassFinder.fillIn(ClassFinder.java:402)
at jdk.compiler/com.sun.tools.javac.code.ClassFinder.complete(ClassFinder.java:302)
at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:703)
at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1471)
at jdk.compiler/com.sun.tools.javac.code.Symbol.apiComplete(Symbol.java:709)
at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$1.getEnclosingType(ClassReader.java:612)
at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationLocator.visitClassType(ClassReader.java:2525)
at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationLocator.visitClassType(ClassReader.java:2501)
at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:1053)
at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4920)
at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationSymbolVisitor.addTypeAnnotations(ClassReader.java:2466)
- backported by
-
JDK-8342159 CompletionFailure in getEnclosingType attaching type annotations
-
- Resolved
-
- relates to
-
JDK-8225377 type annotations are not visible to javac plugins across compilation boundaries
-
- Resolved
-
- links to
-
Commit(master) openjdk/jdk23u/dd1741c1
-
Commit(master) openjdk/jdk/9e282e5c
-
Review(master) openjdk/jdk23u/68
-
Review(master) openjdk/jdk/20495
-
Review(pr/1252) openjdk/jdk21u-dev/1253
(2 links to)