Mon, 11 Nov 2013 17:26:09 +0100
8027375: javac asserts on nested erroneous annotations
Summary: make sure JCAnnotation trees have type != null before annotation processing
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Annotate.java Mon Nov 11 09:47:46 2013 -0500 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Annotate.java Mon Nov 11 17:26:09 2013 +0100 1.3 @@ -255,6 +255,9 @@ 1.4 : attr.attribType(a.annotationType, env)); 1.5 a.type = chk.checkType(a.annotationType.pos(), at, expected); 1.6 if (a.type.isErroneous()) { 1.7 + // Need to make sure nested (anno)trees does not have null as .type 1.8 + attr.postAttr(a); 1.9 + 1.10 if (typeAnnotation) { 1.11 return new Attribute.TypeCompound(a.type, List.<Pair<MethodSymbol,Attribute>>nil(), 1.12 new TypeAnnotationPosition()); 1.13 @@ -265,6 +268,10 @@ 1.14 if ((a.type.tsym.flags() & Flags.ANNOTATION) == 0) { 1.15 log.error(a.annotationType.pos(), 1.16 "not.annotation.type", a.type.toString()); 1.17 + 1.18 + // Need to make sure nested (anno)trees does not have null as .type 1.19 + attr.postAttr(a); 1.20 + 1.21 if (typeAnnotation) { 1.22 return new Attribute.TypeCompound(a.type, List.<Pair<MethodSymbol,Attribute>>nil(), null); 1.23 } else { 1.24 @@ -278,7 +285,7 @@ 1.25 Assign(make.Ident(names.value), args.head); 1.26 } 1.27 ListBuffer<Pair<MethodSymbol,Attribute>> buf = 1.28 - new ListBuffer<Pair<MethodSymbol,Attribute>>(); 1.29 + new ListBuffer<>(); 1.30 for (List<JCExpression> tl = args; tl.nonEmpty(); tl = tl.tail) { 1.31 JCExpression t = tl.head; 1.32 if (!t.hasTag(ASSIGN)) { 1.33 @@ -304,8 +311,7 @@ 1.34 Type result = method.type.getReturnType(); 1.35 Attribute value = enterAttributeValue(result, assign.rhs, env); 1.36 if (!method.type.isErroneous()) 1.37 - buf.append(new Pair<MethodSymbol,Attribute> 1.38 - ((MethodSymbol)method, value)); 1.39 + buf.append(new Pair<>((MethodSymbol)method, value)); 1.40 t.type = result; 1.41 } 1.42 if (typeAnnotation) {
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/annotations/testCrashNestedAnnos/TestCrashNestedAnnos.java Mon Nov 11 17:26:09 2013 +0100 2.3 @@ -0,0 +1,14 @@ 2.4 +/* @test /nodynamiccopyright/ 2.5 + * @bug 8027375 2.6 + * @summary Test that javac doesn't assert/crash when there are what looks to 2.7 + * be annotations nested inside erroneous annotations. 2.8 + * @compile/fail/ref=TestCrashNestedAnnos.out -XDrawDiagnostics TestCrashNestedAnnos.java 2.9 + */ 2.10 +public class TestCrashNestedAnnos { 2.11 + // A and B are not annotation types 2.12 + @A(@A1()) int foo() {} 2.13 + @B(@B1()) int bar() {} 2.14 +} 2.15 + 2.16 +class B {} 2.17 +class B1 {}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/annotations/testCrashNestedAnnos/TestCrashNestedAnnos.out Mon Nov 11 17:26:09 2013 +0100 3.3 @@ -0,0 +1,3 @@ 3.4 +TestCrashNestedAnnos.java:9:6: compiler.err.cant.resolve.location: kindname.class, A, , , (compiler.misc.location: kindname.class, TestCrashNestedAnnos, null) 3.5 +TestCrashNestedAnnos.java:10:6: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: B, java.lang.annotation.Annotation) 3.6 +2 errors