JDK-8354893 : [REDO BACKPORT] javac crashes while adding type annotations to the return type of a constructor (JDK-8320001)
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 21.0.8
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2025-04-16
  • Updated: 2025-04-21
  • Resolved: 2025-04-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21
21.0.8 b26Fixed
Related Reports
Cloners :  
Relates :  
Relates :  
Description
It's observed that some of the JCK tests related to Annotation processing are failing in JDK 22-b23 with "java.lang.AssertionError: Cannot add metadata to this type: VOID"
Possibly a regression caused by - https://bugs.openjdk.org/browse/JDK-8225377 

The tests are passing with JDK22-b22.

Attaching the sample AnnotationProcessor with sample target class file (Tester)

Here is the observation :
====

With b-22 ( Tester class successfully parsed by Annotation Processor)
====
/scratch/jdk-cache/22/22/jdk-22/bin/javac -processor  AnnoProc Tester
init...
process...
  annotations []

With b-23 ( java.lang.AssertionError: Cannot add metadata to this type: VOID )
====

 /scratch/jdk-cache/22/23/jdk-22/bin/javac -processor  AnnoProc Tester
An exception has occurred in the compiler (22-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.
java.lang.AssertionError: Cannot add metadata to this type: VOID
        at jdk.compiler/com.sun.tools.javac.code.Type.cloneWithMetadata(Type.java:351)
        at jdk.compiler/com.sun.tools.javac.code.Type.addMetadata(Type.java:390)
        at jdk.compiler/com.sun.tools.javac.code.Type.annotatedType(Type.java:456)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationTypeMapping.reannotate(ClassReader.java:2548)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationTypeMapping.visitType(ClassReader.java:2568)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationTypeMapping.visitType(ClassReader.java:2523)
        at jdk.compiler/com.sun.tools.javac.code.Type.accept(Type.java:223)
        at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4894)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationSymbolVisitor.addTypeAnnotations(ClassReader.java:2426)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationSymbolVisitor.addTypeAnnotations(ClassReader.java:2394)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationSymbolVisitor.visitMethodSymbol(ClassReader.java:2335)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationSymbolVisitor.visitMethodSymbol(ClassReader.java:2286)
        at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.accept(Symbol.java:2271)
        at jdk.compiler/com.sun.tools.javac.code.Types$DefaultSymbolVisitor.visit(Types.java:4921)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassReader.addTypeAnnotationsToSymbol(ClassReader.java:2283)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassReader$TypeAnnotationCompleter.run(ClassReader.java:2266)
        at jdk.compiler/com.sun.tools.javac.comp.Annotate.flush(Annotate.java:191)
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.complete(ClassFinder.java:322)
        at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:682)
        at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1418)
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.loadClass(ClassFinder.java:446)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.resolveBinaryNameOrIdent(JavaCompiler.java:730)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.resolveBinaryNameOrIdent(JavaCompiler.java:719)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1239)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:319)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:178)
        at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:66)
        at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:52)


 




Comments
Changeset: b2225c8c Branch: master Author: Liam Miller-Cushon <cushon@openjdk.org> Committer: Paul Hohensee <phh@openjdk.org> Date: 2025-04-21 16:14:50 +0000 URL: https://git.openjdk.org/jdk21u-dev/commit/b2225c8c491e9a5f4f6d2ef14338369d681d6110
21-04-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk21u-dev/pull/1675 Date: 2025-04-17 15:51:15 +0000
17-04-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk21u-dev/pull/1670 Date: 2025-04-16 19:20:25 +0000
17-04-2025

This got backed out of the JDK 21.0.2 release with JDK-8322883. Thus, a JDK 21-specific redo bug. In later JDKs the fix JDK-8320001 (for which this is a redo), didn't get backed out.
17-04-2025

[jdk21u-fix-request] Approval Request from Liam Miller-Cushon for backport. This is a follow-on fix related to the backport of JDK-8341779 (allow accessing type-use annotations on types loaded from class files). Affected tests pass. The patch applies cleanly, I resolved a trivial merge conflict due to changes in context lines.
16-04-2025