changeset 2652:4d2222373842

8062359: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass Reviewed-by: jlahoda, vromero
author jfranck
date Wed, 26 Nov 2014 12:16:47 +0100
parents b5c8adb2206a
children 4721674bb051
files src/share/classes/com/sun/tools/javac/comp/Attr.java test/tools/javac/8062359/UnresolvableClassNPEInAttrTest.java test/tools/javac/8062359/UnresolvableClassNPEInAttrTest.out
diffstat 3 files changed, 28 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Nov 25 13:37:34 2014 -0800
+++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Nov 26 12:16:47 2014 +0100
@@ -4503,14 +4503,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/test/tools/javac/8062359/UnresolvableClassNPEInAttrTest.java	Wed Nov 26 12:16:47 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/test/tools/javac/8062359/UnresolvableClassNPEInAttrTest.out	Wed Nov 26 12:16:47 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