diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java index 40ba3152958..366e16f1da3 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java @@ -556,7 +556,6 @@ public class Annotate { if (expectedElementType.hasTag(ARRAY)) { return getAnnotationArrayValue(expectedElementType, tree, env); - } //error recovery @@ -708,11 +707,15 @@ public class Annotate { } JCNewArray na = (JCNewArray)tree; + List elems = na.elems; if (na.elemtype != null) { log.error(na.elemtype.pos(), Errors.NewNotAllowedInAnnotation); + if (elems == null) { + elems = List.nil(); + } } ListBuffer buf = new ListBuffer<>(); - for (List l = na.elems; l.nonEmpty(); l=l.tail) { + for (List l = elems; l.nonEmpty(); l = l.tail) { buf.append(attributeAnnotationValue(types.elemtype(expectedElementType), l.head, env)); diff --git a/test/langtools/tools/javac/T8320144.java b/test/langtools/tools/javac/T8320144.java new file mode 100644 index 00000000000..6bd3c4ab66d --- /dev/null +++ b/test/langtools/tools/javac/T8320144.java @@ -0,0 +1,19 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8320144 + * @summary Compilation crashes when a custom annotation with invalid default value is used + * @compile/fail/ref=T8320144.out -XDrawDiagnostics T8320144.java + */ +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +public class T8320144 { + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE}) + public @interface TestAnnotation { + public String[] excludeModules() default new String[0]; + public String[] value() default new String[] { 3 }; + } +} diff --git a/test/langtools/tools/javac/T8320144.out b/test/langtools/tools/javac/T8320144.out new file mode 100644 index 00000000000..cb09e379cd1 --- /dev/null +++ b/test/langtools/tools/javac/T8320144.out @@ -0,0 +1,4 @@ +T8320144.java:16:54: compiler.err.new.not.allowed.in.annotation +T8320144.java:17:45: compiler.err.new.not.allowed.in.annotation +T8320144.java:17:56: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.String) +3 errors