aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjfranck <none@none>2013-11-11 17:26:09 +0100
committerjfranck <none@none>2013-11-11 17:26:09 +0100
commitc7988919de73eb7a431be93055298b4613811e86 (patch)
treef3757268cbb5c0b3a9cb925abade928a6ca324ad
parent415ca8aa977a85e4637c41a74603f73885fb5e44 (diff)
8027375: javac asserts on nested erroneous annotations
Summary: make sure JCAnnotation trees have type != null before annotation processing Reviewed-by: jjg
-rw-r--r--src/share/classes/com/sun/tools/javac/comp/Annotate.java12
-rw-r--r--test/tools/javac/annotations/testCrashNestedAnnos/TestCrashNestedAnnos.java14
-rw-r--r--test/tools/javac/annotations/testCrashNestedAnnos/TestCrashNestedAnnos.out3
3 files changed, 26 insertions, 3 deletions
diff --git a/src/share/classes/com/sun/tools/javac/comp/Annotate.java b/src/share/classes/com/sun/tools/javac/comp/Annotate.java
index bc0903fd..4e1714aa 100644
--- a/src/share/classes/com/sun/tools/javac/comp/Annotate.java
+++ b/src/share/classes/com/sun/tools/javac/comp/Annotate.java
@@ -255,6 +255,9 @@ public class Annotate {
: 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.<Pair<MethodSymbol,Attribute>>nil(),
new TypeAnnotationPosition());
@@ -265,6 +268,10 @@ public class Annotate {
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.<Pair<MethodSymbol,Attribute>>nil(), null);
} else {
@@ -278,7 +285,7 @@ public class Annotate {
Assign(make.Ident(names.value), args.head);
}
ListBuffer<Pair<MethodSymbol,Attribute>> buf =
- new ListBuffer<Pair<MethodSymbol,Attribute>>();
+ new ListBuffer<>();
for (List<JCExpression> tl = args; tl.nonEmpty(); tl = tl.tail) {
JCExpression t = tl.head;
if (!t.hasTag(ASSIGN)) {
@@ -304,8 +311,7 @@ public class Annotate {
Type result = method.type.getReturnType();
Attribute value = enterAttributeValue(result, assign.rhs, env);
if (!method.type.isErroneous())
- buf.append(new Pair<MethodSymbol,Attribute>
- ((MethodSymbol)method, value));
+ buf.append(new Pair<>((MethodSymbol)method, value));
t.type = result;
}
if (typeAnnotation) {
diff --git a/test/tools/javac/annotations/testCrashNestedAnnos/TestCrashNestedAnnos.java b/test/tools/javac/annotations/testCrashNestedAnnos/TestCrashNestedAnnos.java
new file mode 100644
index 00000000..5c7a4a33
--- /dev/null
+++ b/test/tools/javac/annotations/testCrashNestedAnnos/TestCrashNestedAnnos.java
@@ -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 --git a/test/tools/javac/annotations/testCrashNestedAnnos/TestCrashNestedAnnos.out b/test/tools/javac/annotations/testCrashNestedAnnos/TestCrashNestedAnnos.out
new file mode 100644
index 00000000..af34ecfd
--- /dev/null
+++ b/test/tools/javac/annotations/testCrashNestedAnnos/TestCrashNestedAnnos.out
@@ -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