-
Bug
-
Resolution: Fixed
-
P3
-
19
-
b11
In the following example, javac crashes when compiling a file that references an annotation with a @Target containing an invalid ElementType.
The class file is not well formed, but the compiler should handle it without crashing.
I think this should be a warning, but not a fatal error. The values in ElementType are updated for new language features, so this is similar this crash involve a Java 8 compilation that saw a reference to ElementType.MODULE: https://bugs.openjdk.org/browse/JDK-8295314
```
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Gen {
public static void main(String[] args) throws Exception {
Files.write(Paths.get("A.class"), dump());
}
private static byte[] dump() {
ClassWriter classWriter = new ClassWriter(0);
classWriter.visit(
Opcodes.V11,
Opcodes.ACC_ANNOTATION | Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE,
"A",
null,
"java/lang/Object",
new String[] {"java/lang/annotation/Annotation"});
classWriter.visitSource("A.java", null);
AnnotationVisitor target = classWriter.visitAnnotation("Ljava/lang/annotation/Target;", true);
AnnotationVisitor value = target.visitArray("value");
value.visitEnum(null, "Ljava/lang/annotation/ElementType;", "FIELD");
value.visitEnum(null, "Ljava/lang/annotation/ElementType;", "NO_SUCH");
value.visitEnd();
target.visitEnd();
classWriter.visitEnd();
return classWriter.toByteArray();
}
}
```
```
class B {
@A Object o;
}
```
```
$ javac -cp asm-9.4.jar:asm-util-9.4.jar Gen.java
$ java -cp asm-9.4.jar:asm-util-9.4.jar:. Gen
$ javac -fullversion B.java
javac full version "19-ea+34-2229"
warning: unknown enum constant ElementType.NO_SUCH
warning: unknown enum constant ElementType.NO_SUCH
2 warnings
An exception has occurred in the compiler (19-ea). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.AssertionError: annotationTargetType(): unrecognized Attribute name NO_SUCH (class com.sun.tools.javac.util.SharedNameTable$NameImpl)
at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:162)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations.targetToAnnotationType(TypeAnnotations.java:256)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations.lambda$annotationTargetType$3(TypeAnnotations.java:190)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1921)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.reduce(ReferencePipeline.java:657)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations.annotationTargetType(TypeAnnotations.java:191)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.separateAnnotationsKinds(TypeAnnotations.java:316)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitVarDef(TypeAnnotations.java:1269)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1018)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:294)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitClassDef(TypeAnnotations.java:1142)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:810)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:294)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations.lambda$organizeTypeAnnotationsSignatures$0(TypeAnnotations.java:131)
at jdk.compiler/com.sun.tools.javac.comp.Annotate.flush(Annotate.java:198)
at jdk.compiler/com.sun.tools.javac.comp.Annotate.unblockAnnotations(Annotate.java:145)
at jdk.compiler/com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:158)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.enterDone(JavaCompiler.java:1741)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:1044)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:917)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
```
The class file is not well formed, but the compiler should handle it without crashing.
I think this should be a warning, but not a fatal error. The values in ElementType are updated for new language features, so this is similar this crash involve a Java 8 compilation that saw a reference to ElementType.MODULE: https://bugs.openjdk.org/browse/JDK-8295314
```
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Gen {
public static void main(String[] args) throws Exception {
Files.write(Paths.get("A.class"), dump());
}
private static byte[] dump() {
ClassWriter classWriter = new ClassWriter(0);
classWriter.visit(
Opcodes.V11,
Opcodes.ACC_ANNOTATION | Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE,
"A",
null,
"java/lang/Object",
new String[] {"java/lang/annotation/Annotation"});
classWriter.visitSource("A.java", null);
AnnotationVisitor target = classWriter.visitAnnotation("Ljava/lang/annotation/Target;", true);
AnnotationVisitor value = target.visitArray("value");
value.visitEnum(null, "Ljava/lang/annotation/ElementType;", "FIELD");
value.visitEnum(null, "Ljava/lang/annotation/ElementType;", "NO_SUCH");
value.visitEnd();
target.visitEnd();
classWriter.visitEnd();
return classWriter.toByteArray();
}
}
```
```
class B {
@A Object o;
}
```
```
$ javac -cp asm-9.4.jar:asm-util-9.4.jar Gen.java
$ java -cp asm-9.4.jar:asm-util-9.4.jar:. Gen
$ javac -fullversion B.java
javac full version "19-ea+34-2229"
warning: unknown enum constant ElementType.NO_SUCH
warning: unknown enum constant ElementType.NO_SUCH
2 warnings
An exception has occurred in the compiler (19-ea). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.AssertionError: annotationTargetType(): unrecognized Attribute name NO_SUCH (class com.sun.tools.javac.util.SharedNameTable$NameImpl)
at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:162)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations.targetToAnnotationType(TypeAnnotations.java:256)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations.lambda$annotationTargetType$3(TypeAnnotations.java:190)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1921)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.reduce(ReferencePipeline.java:657)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations.annotationTargetType(TypeAnnotations.java:191)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.separateAnnotationsKinds(TypeAnnotations.java:316)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitVarDef(TypeAnnotations.java:1269)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1018)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:294)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitClassDef(TypeAnnotations.java:1142)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:810)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:294)
at jdk.compiler/com.sun.tools.javac.code.TypeAnnotations.lambda$organizeTypeAnnotationsSignatures$0(TypeAnnotations.java:131)
at jdk.compiler/com.sun.tools.javac.comp.Annotate.flush(Annotate.java:198)
at jdk.compiler/com.sun.tools.javac.comp.Annotate.unblockAnnotations(Annotate.java:145)
at jdk.compiler/com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:158)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.enterDone(JavaCompiler.java:1741)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:1044)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:917)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
```
- duplicates
-
JDK-8295314 javac crashes when an annotation with a MODULE target is used on a method
-
- Closed
-
- relates to
-
JDK-8295314 javac crashes when an annotation with a MODULE target is used on a method
-
- Closed
-