Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8332497

javac prints an AssertionError when annotation processing runs on program with module imports

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 23
    • 23
    • tools
    • None
    • b25

      Consider this code:
      ---
      import module java.base;

      import javax.annotation.processing.AbstractProcessor;
      import javax.annotation.processing.RoundEnvironment;
      import javax.annotation.processing.SupportedAnnotationTypes;
      import javax.lang.model.element.TypeElement;

      @SupportedAnnotationTypes("*")
      public class AP extends AbstractProcessor {

          @Override
          public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
              return false;
          }
          
      }
      ---

      Compiling this while running itself as an annotation processor crashes:
      ---
      $ javac --enable-preview -source 23 AP.java
      Note: AP.java uses preview features of Java SE 23.
      Note: Recompile with -Xlint:preview for details.
      $ javac -J--enable-preview --enable-preview -source 23 -processor AP AP.java
      warning: No SupportedSourceVersion annotation found on AP, returning RELEASE_6.
      warning: Supported source version 'RELEASE_6' from annotation processor 'AP' less than -source '23'
      2 warnings
      An exception has occurred in the compiler (23-internal). 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
              at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitTree(TreeScanner.java:415)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$Visitor.visitModuleImport(JCTree.java:3528)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCModuleImport.accept(JCTree.java:720)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
              at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$1.scan(JavacProcessingEnvironment.java:1592)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:58)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitTopLevel(TreeScanner.java:67)
              at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$1.visitTopLevel(JavacProcessingEnvironment.java:1613)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:553)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
              at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$1.scan(JavacProcessingEnvironment.java:1592)
              at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.newRound(JavacProcessingEnvironment.java:1314)
              at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.<init>(JavacProcessingEnvironment.java:1110)
              at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.next(JavacProcessingEnvironment.java:1151)
              at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1389)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1274)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:947)
              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)
      printing javac parameters to: /tmp/ap-module-imports/javac.20240519_083714.args
      ---

            jlahoda Jan Lahoda
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: