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

NullPointerException in javac on record with annotation

XMLWordPrintable

    • x86_64
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      MacBook Pro 16 Inch, MacOS Catalina 10.15.5
      javac 15-ea build 32 (openjdk-15-ea+32_osx-x64_bin.tar.gz)
      javac 14.0.2 (openjdk-14.0.2_osx-x64_bin.tar)


      A DESCRIPTION OF THE PROBLEM :
      Compilation of a record class using the java.io.Serial annotation on a static final field fails with a NullPointerException.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the provided code with javac with the command line parameters `--enable-preview -release 15`:

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      record compiled without issues
      ACTUAL -
      An exception has occurred in the compiler (15-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.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Symbol$RecordComponent.getMetadata()" because "rc" is null
              at jdk.compiler/com.sun.tools.javac.comp.Check.validateAnnotation(Check.java:2940)
              at jdk.compiler/com.sun.tools.javac.comp.Check.validateAnnotations(Check.java:2896)
              at jdk.compiler/com.sun.tools.javac.comp.Annotate.lambda$annotateLater$1(Annotate.java:279)
              at jdk.compiler/com.sun.tools.javac.comp.Annotate.flush(Annotate.java:200)
              at jdk.compiler/com.sun.tools.javac.comp.Annotate.unblockAnnotations(Annotate.java:144)
              at jdk.compiler/com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:157)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.enterDone(JavaCompiler.java:1750)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:1071)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:936)
              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:59)
              at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:45)

      In Oracle OpenJDK 14.0.2 a similar exception is thrown:

      An exception has occurred in the compiler (14.0.2). 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.NullPointerException
              at jdk.compiler/com.sun.tools.javac.comp.Check.validateAnnotation(Check.java:2912)
              at jdk.compiler/com.sun.tools.javac.comp.Check.validateAnnotations(Check.java:2868)
              at jdk.compiler/com.sun.tools.javac.comp.Annotate.lambda$annotateLater$1(Annotate.java:279)
              at jdk.compiler/com.sun.tools.javac.comp.Annotate.flush(Annotate.java:200)
              at jdk.compiler/com.sun.tools.javac.comp.Annotate.unblockAnnotations(Annotate.java:144)
              at jdk.compiler/com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:157)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.enterDone(JavaCompiler.java:1752)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:1073)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:936)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:316)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
              at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
              at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)


      ---------- BEGIN SOURCE ----------
      import java.io.Serial;
      import java.io.Serializable;

      record R1(int i) implements Serializable {
          @Serial private static final long serialVersionUID = 1;
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Remove the @Serial annotation from the field and the program compiles without problems.

      FREQUENCY : always


            adev Anupam Dev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: