8062359: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass
authorjfranck
Fri, 21 Nov 2014 12:36:21 +0100
changeset 27851 5f28577d20f6
parent 27850 d27ca106daa4
child 27852 2e6ad0e4fe20
8062359: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass Reviewed-by: jlahoda, vromero
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/test/tools/javac/8062359/UnresolvableClassNPEInAttrTest.java
langtools/test/tools/javac/8062359/UnresolvableClassNPEInAttrTest.out
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Nov 20 14:23:31 2014 -0800
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Nov 21 12:36:21 2014 +0100
@@ -4490,14 +4490,15 @@
             super.visitTypeTest(tree);
         }
         public void visitNewClass(JCNewClass tree) {
-            if (tree.clazz.hasTag(ANNOTATED_TYPE)) {
-                checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations,
-                        tree.clazz.type.tsym);
-            }
-            if (tree.def != null) {
-                checkForDeclarationAnnotations(tree.def.mods.annotations, tree.clazz.type.tsym);
-            }
-            if (tree.clazz.type != null) {
+            if (tree.clazz != null && tree.clazz.type != null) {
+                if (tree.clazz.hasTag(ANNOTATED_TYPE)) {
+                    checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations,
+                            tree.clazz.type.tsym);
+                }
+                if (tree.def != null) {
+                    checkForDeclarationAnnotations(tree.def.mods.annotations, tree.clazz.type.tsym);
+                }
+
                 validateAnnotatedType(tree.clazz, tree.clazz.type);
             }
             super.visitNewClass(tree);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/8062359/UnresolvableClassNPEInAttrTest.java	Fri Nov 21 12:36:21 2014 +0100
@@ -0,0 +1,17 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8062359
+ * @summary NullPointerException in Attr when type-annotating an anonymous
+ *          inner class in an unresolvable class
+ * @compile/fail/ref=UnresolvableClassNPEInAttrTest.out -XDrawDiagnostics UnresolvableClassNPEInAttrTest.java
+ */
+
+public class UnresolvableClassNPEInAttrTest {
+    public static void main(String[] args) {
+        new Undefined() {
+            void test() {
+                new Object() {};
+            }
+        };
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/8062359/UnresolvableClassNPEInAttrTest.out	Fri Nov 21 12:36:21 2014 +0100
@@ -0,0 +1,2 @@
+UnresolvableClassNPEInAttrTest.java:11:13: compiler.err.cant.resolve.location: kindname.class, Undefined, , , (compiler.misc.location: kindname.class, UnresolvableClassNPEInAttrTest, null)
+1 error