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

NPE in JavacProcessingEnvironment for missing enum constructor body

XMLWordPrintable

    • b20

        javac crashes on the following invalid input when annotation processing is enabled.

        The correct error is reported with annotation processing disabled:

        T.java:4: error: missing method body, or declare abstract
          T(String one);
          ^

        === P.java
        import java.util.Set;
        import javax.annotation.processing.AbstractProcessor;
        import javax.annotation.processing.RoundEnvironment;
        import javax.annotation.processing.SupportedAnnotationTypes;
        import javax.lang.model.SourceVersion;
        import javax.lang.model.element.TypeElement;

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

          @Override
          public SourceVersion getSupportedSourceVersion() {
            return SourceVersion.latestSupported();
          }

          @Override
          public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
            return false;
          }
        }
        === T.java
        enum T {
          ONE("");

          T(String one);

          final String one;
        }
        ===

        $ javac P.java
        $ javac -fullversion -processor P T.java
        javac full version "21-ea+17-1421"
        An exception has occurred in the compiler (21-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.NullPointerException: Cannot read field "stats" because "node.body" is null
                at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$1.visitMethodDef(JavacProcessingEnvironment.java:1648)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:912)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
                at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$1.scan(JavacPro

              vromero Vicente Arturo Romero Zaldivar
              cushon Liam Miller-Cushon
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: