# HG changeset patch # User jfranck # Date 1384187169 -3600 # Node ID b3fcc9c0fea3253fed3eaf69fbbb943737952d5c # Parent d363f367d4c0280364e8f4f6619226bacb2c475a 8027375: javac asserts on nested erroneous annotations Summary: make sure JCAnnotation trees have type != null before annotation processing Reviewed-by: jjg diff -r d363f367d4c0 -r b3fcc9c0fea3 langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java Mon Nov 11 09:47:46 2013 -0500 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java Mon Nov 11 17:26:09 2013 +0100 @@ -255,6 +255,9 @@ : attr.attribType(a.annotationType, env)); a.type = chk.checkType(a.annotationType.pos(), at, expected); if (a.type.isErroneous()) { + // Need to make sure nested (anno)trees does not have null as .type + attr.postAttr(a); + if (typeAnnotation) { return new Attribute.TypeCompound(a.type, List.>nil(), new TypeAnnotationPosition()); @@ -265,6 +268,10 @@ if ((a.type.tsym.flags() & Flags.ANNOTATION) == 0) { log.error(a.annotationType.pos(), "not.annotation.type", a.type.toString()); + + // Need to make sure nested (anno)trees does not have null as .type + attr.postAttr(a); + if (typeAnnotation) { return new Attribute.TypeCompound(a.type, List.>nil(), null); } else { @@ -278,7 +285,7 @@ Assign(make.Ident(names.value), args.head); } ListBuffer> buf = - new ListBuffer>(); + new ListBuffer<>(); for (List tl = args; tl.nonEmpty(); tl = tl.tail) { JCExpression t = tl.head; if (!t.hasTag(ASSIGN)) { @@ -304,8 +311,7 @@ Type result = method.type.getReturnType(); Attribute value = enterAttributeValue(result, assign.rhs, env); if (!method.type.isErroneous()) - buf.append(new Pair - ((MethodSymbol)method, value)); + buf.append(new Pair<>((MethodSymbol)method, value)); t.type = result; } if (typeAnnotation) { diff -r d363f367d4c0 -r b3fcc9c0fea3 langtools/test/tools/javac/annotations/testCrashNestedAnnos/TestCrashNestedAnnos.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/testCrashNestedAnnos/TestCrashNestedAnnos.java Mon Nov 11 17:26:09 2013 +0100 @@ -0,0 +1,14 @@ +/* @test /nodynamiccopyright/ + * @bug 8027375 + * @summary Test that javac doesn't assert/crash when there are what looks to + * be annotations nested inside erroneous annotations. + * @compile/fail/ref=TestCrashNestedAnnos.out -XDrawDiagnostics TestCrashNestedAnnos.java + */ +public class TestCrashNestedAnnos { + // A and B are not annotation types + @A(@A1()) int foo() {} + @B(@B1()) int bar() {} +} + +class B {} +class B1 {} diff -r d363f367d4c0 -r b3fcc9c0fea3 langtools/test/tools/javac/annotations/testCrashNestedAnnos/TestCrashNestedAnnos.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/testCrashNestedAnnos/TestCrashNestedAnnos.out Mon Nov 11 17:26:09 2013 +0100 @@ -0,0 +1,3 @@ +TestCrashNestedAnnos.java:9:6: compiler.err.cant.resolve.location: kindname.class, A, , , (compiler.misc.location: kindname.class, TestCrashNestedAnnos, null) +TestCrashNestedAnnos.java:10:6: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: B, java.lang.annotation.Annotation) +2 errors