Wed, 26 Nov 2014 12:16:47 +0100
8062359: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass
Reviewed-by: jlahoda, vromero
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Nov 25 13:37:34 2014 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Nov 26 12:16:47 2014 +0100 1.3 @@ -4503,14 +4503,15 @@ 1.4 super.visitTypeTest(tree); 1.5 } 1.6 public void visitNewClass(JCNewClass tree) { 1.7 - if (tree.clazz.hasTag(ANNOTATED_TYPE)) { 1.8 - checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations, 1.9 - tree.clazz.type.tsym); 1.10 - } 1.11 - if (tree.def != null) { 1.12 - checkForDeclarationAnnotations(tree.def.mods.annotations, tree.clazz.type.tsym); 1.13 - } 1.14 - if (tree.clazz.type != null) { 1.15 + if (tree.clazz != null && tree.clazz.type != null) { 1.16 + if (tree.clazz.hasTag(ANNOTATED_TYPE)) { 1.17 + checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations, 1.18 + tree.clazz.type.tsym); 1.19 + } 1.20 + if (tree.def != null) { 1.21 + checkForDeclarationAnnotations(tree.def.mods.annotations, tree.clazz.type.tsym); 1.22 + } 1.23 + 1.24 validateAnnotatedType(tree.clazz, tree.clazz.type); 1.25 } 1.26 super.visitNewClass(tree);
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/8062359/UnresolvableClassNPEInAttrTest.java Wed Nov 26 12:16:47 2014 +0100 2.3 @@ -0,0 +1,17 @@ 2.4 +/* 2.5 + * @test /nodynamiccopyright/ 2.6 + * @bug 8062359 2.7 + * @summary NullPointerException in Attr when type-annotating an anonymous 2.8 + * inner class in an unresolvable class 2.9 + * @compile/fail/ref=UnresolvableClassNPEInAttrTest.out -XDrawDiagnostics UnresolvableClassNPEInAttrTest.java 2.10 + */ 2.11 + 2.12 +public class UnresolvableClassNPEInAttrTest { 2.13 + public static void main(String[] args) { 2.14 + new Undefined() { 2.15 + void test() { 2.16 + new Object() {}; 2.17 + } 2.18 + }; 2.19 + } 2.20 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/8062359/UnresolvableClassNPEInAttrTest.out Wed Nov 26 12:16:47 2014 +0100 3.3 @@ -0,0 +1,2 @@ 3.4 +UnresolvableClassNPEInAttrTest.java:11:13: compiler.err.cant.resolve.location: kindname.class, Undefined, , , (compiler.misc.location: kindname.class, UnresolvableClassNPEInAttrTest, null) 3.5 +1 error