javac 11.0.6 NullPointerException when a type param refers to missing type
Vitaly Davidovich
vitalyd at gmail.com
Wed Mar 18 23:47:55 UTC 2020
Hi all,
I'd like to report a bug against javac 11.0.6 (and possibly later, but I
don't readily have access to newer versions).
To reproduce:
Create the following 3 source files:
////// A.java
public class A<T extends B<T>> {
public void foo() {}
}
////// B.java
public class B<T> {}
////// C.java
public class C {
public static void crashJavaC(A a) {
a.foo(null);
}
}
$ javac A.java B.java
$ rm B.java B.class
$ javac C.java
An exception has occurred in the compiler (11.0.6). 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 and the
following diagnostic in your report. Thank you.
java.lang.NullPointerException
at
jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitSelect(TransTypes.java:811)
at
jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2114)
at
jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at
jdk.compiler/com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:454)
at
jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitApply(TransTypes.java:622)
at
jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1634)
at
jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at
jdk.compiler/com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:454)
at
jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitExec(TransTypes.java:599)
at
jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1452)
at
jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at
jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
at
jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:167)
at
jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1020)
at
jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at
jdk.compiler/com.sun.tools.javac.comp.TransTypes.translate(TransTypes.java:454)
at
jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitMethodDef(TransTypes.java:489)
at
jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
at
jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at
jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
at
jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitClassDef(TreeTranslator.java:139)
at
jdk.compiler/com.sun.tools.javac.comp.TransTypes.translateClass(TransTypes.java:918)
at
jdk.compiler/com.sun.tools.javac.comp.TransTypes.visitClassDef(TransTypes.java:475)
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.TransTypes.translate(TransTypes.java:454)
at
jdk.compiler/com.sun.tools.javac.comp.TransTypes.translateTopLevelClass(TransTypes.java:942)
at
jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1553)
at
jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1432)
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)
If B.java *is* present, we get the expected compilation error:
$ javac C.java
C.java:3: error: method foo in class A<T> cannot be applied to given types;
a.foo(null);
^
required: no arguments
found: <null>
reason: actual and formal argument lists differ in length
where T is a type-variable:
T extends B<T> declared in class A
1 error
The repro is (purposely) contrived. The real case came up when build
infrastructure prevented the source path of B.java from being observed when
building C.java.
I assume javac shouldn't crash with an NPE, and should instead provide a
compilation error pointing out that B symbol is not found (or similar).
Let me know if you have any questions.
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20200318/a1463a9f/attachment-0001.htm>
More information about the compiler-dev
mailing list