ADDITIONAL SYSTEM INFORMATION :
Windows 11, javac 11.0.21
A DESCRIPTION OF THE PROBLEM :
See code example and below stacktrace. The attempted compilation of the attached code fails with a compiler exception. Specifically, when a method obtains a field from a forward-reference to a static variable of type Class that is initialized with SomeMissingClass.class further below, and attempts to pass this reference to another method, the compilation of the class fails with a java.lang.AssertionError:
>javac HelloSunBug.java
An exception has occurred in the compiler (11.0.21). 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 and the following diagnostic in your report. Thank you.
java.lang.AssertionError
at jdk.compiler/com.sun.tools.javac.comp.Lower.classOfType(Lower.java:1882)
at jdk.compiler/com.sun.tools.javac.comp.Lower.classOf(Lower.java:1860)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitSelect(Lower.java:3588)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2130)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2064)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2075)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitVarDef(Lower.java:3295)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:972)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2064)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2202)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2064)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2083)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:3678)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1575)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1428)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached class with javac in ersion 11.0.21
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
HelloSunBug.java:9: error: cannot find symbol
final static Class SOMECLASS = IDontExist.class;
^
symbol: class IDontExist
location: class HelloSunBug
1 error
ACTUAL -
An exception has occurred in the compiler (11.0.21). 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 and the following diagnostic in your report. Thank you.
java.lang.AssertionError
at jdk.compiler/com.sun.tools.javac.comp.Lower.classOfType(Lower.java:1882)
at jdk.compiler/com.sun.tools.javac.comp.Lower.classOf(Lower.java:1860)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitSelect(Lower.java:3588)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2130)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2064)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2075)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitVarDef(Lower.java:3295)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:972)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2064)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2202)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2064)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2083)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:3678)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1575)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1428)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
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 ----------
public class HelloSunBug {
public static void referToAnyFieldOfAMissingClass() {
useField(SOMECLASS.getCanonicalName());
}
public static void useField(Object doesnTMatter) {}
final static Class SOMECLASS = IDontExist.class;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Initialize the static Class variable before referencing it to obtain a proper error message
FREQUENCY : always
Windows 11, javac 11.0.21
A DESCRIPTION OF THE PROBLEM :
See code example and below stacktrace. The attempted compilation of the attached code fails with a compiler exception. Specifically, when a method obtains a field from a forward-reference to a static variable of type Class that is initialized with SomeMissingClass.class further below, and attempts to pass this reference to another method, the compilation of the class fails with a java.lang.AssertionError:
>javac HelloSunBug.java
An exception has occurred in the compiler (11.0.21). 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 and the following diagnostic in your report. Thank you.
java.lang.AssertionError
at jdk.compiler/com.sun.tools.javac.comp.Lower.classOfType(Lower.java:1882)
at jdk.compiler/com.sun.tools.javac.comp.Lower.classOf(Lower.java:1860)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitSelect(Lower.java:3588)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2130)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2064)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2075)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitVarDef(Lower.java:3295)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:972)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2064)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2202)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2064)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2083)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:3678)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1575)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1428)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached class with javac in ersion 11.0.21
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
HelloSunBug.java:9: error: cannot find symbol
final static Class SOMECLASS = IDontExist.class;
^
symbol: class IDontExist
location: class HelloSunBug
1 error
ACTUAL -
An exception has occurred in the compiler (11.0.21). 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 and the following diagnostic in your report. Thank you.
java.lang.AssertionError
at jdk.compiler/com.sun.tools.javac.comp.Lower.classOfType(Lower.java:1882)
at jdk.compiler/com.sun.tools.javac.comp.Lower.classOf(Lower.java:1860)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitSelect(Lower.java:3588)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2130)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2064)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2075)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitVarDef(Lower.java:3295)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:972)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2064)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2202)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2064)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2083)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:3678)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1575)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1428)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
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 ----------
public class HelloSunBug {
public static void referToAnyFieldOfAMissingClass() {
useField(SOMECLASS.getCanonicalName());
}
public static void useField(Object doesnTMatter) {}
final static Class SOMECLASS = IDontExist.class;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Initialize the static Class variable before referencing it to obtain a proper error message
FREQUENCY : always