-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
14, 15
-
x86_64
-
linux_ubuntu, windows_10
-
Verified
ADDITIONAL SYSTEM INFORMATION :
$ uname -a
Linux Nelkinda-Blade-Stealth-2 5.4.0-40-generic #44-Ubuntu SMP Tue Jun 23 00:01:04 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
$ /opt/java/jdk-14.0.2/bin/javac -version
javac 14.0.2
A DESCRIPTION OF THE PROBLEM :
Given a record class with a constant field,
And that constant field has an annotation,
When compiling that class,
Then the compilation throws an exception.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a record class with a field:
record RecordClass() {
@SuppressWarnings("foo")
private static final int FIELD = 42;
}
Compile that record class, for example, with javac --enable-preview -source 14 -target 14 RecordClass.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The record is compiled successfully into a class file.
ACTUAL -
The compiler throws a NullPointerException with the following stack trace:
$ javac --enable-preview -source 14 -target 14 *.java
Note: RecordClass.java uses preview language features.
Note: Recompile with -Xlint:preview for details.
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)
printing javac parameters to: /home/christian.hujer/git/christianhujer/java-bug-record-field-annotation/javac.20200720_160831.args
---------- BEGIN SOURCE ----------
record RecordClass() {
@SuppressWarnings("foo")
private static final int FIELD = 42;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
No general workaround is known at this time. In specific situations, like using @SuppressWarnings, tool might offer tool-specific workarounds, for example, using a warning suppression comment instead of the @SuppressWarnings annotation.
FREQUENCY : always
$ uname -a
Linux Nelkinda-Blade-Stealth-2 5.4.0-40-generic #44-Ubuntu SMP Tue Jun 23 00:01:04 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
$ /opt/java/jdk-14.0.2/bin/javac -version
javac 14.0.2
A DESCRIPTION OF THE PROBLEM :
Given a record class with a constant field,
And that constant field has an annotation,
When compiling that class,
Then the compilation throws an exception.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a record class with a field:
record RecordClass() {
@SuppressWarnings("foo")
private static final int FIELD = 42;
}
Compile that record class, for example, with javac --enable-preview -source 14 -target 14 RecordClass.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The record is compiled successfully into a class file.
ACTUAL -
The compiler throws a NullPointerException with the following stack trace:
$ javac --enable-preview -source 14 -target 14 *.java
Note: RecordClass.java uses preview language features.
Note: Recompile with -Xlint:preview for details.
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)
printing javac parameters to: /home/christian.hujer/git/christianhujer/java-bug-record-field-annotation/javac.20200720_160831.args
---------- BEGIN SOURCE ----------
record RecordClass() {
@SuppressWarnings("foo")
private static final int FIELD = 42;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
No general workaround is known at this time. In specific situations, like using @SuppressWarnings, tool might offer tool-specific workarounds, for example, using a warning suppression comment instead of the @SuppressWarnings annotation.
FREQUENCY : always
- duplicates
-
JDK-8243057 compilation of annotated static record fields fails with NPE
-
- Resolved
-