mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
8320144: Compilation crashes when a custom annotation with invalid default value is used
Reviewed-by: vromero, jlahoda
This commit is contained in:
parent
50f3124055
commit
90e433d72e
@ -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<JCExpression> elems = na.elems;
|
||||
if (na.elemtype != null) {
|
||||
log.error(na.elemtype.pos(), Errors.NewNotAllowedInAnnotation);
|
||||
if (elems == null) {
|
||||
elems = List.nil();
|
||||
}
|
||||
}
|
||||
ListBuffer<Attribute> buf = new ListBuffer<>();
|
||||
for (List<JCExpression> l = na.elems; l.nonEmpty(); l=l.tail) {
|
||||
for (List<JCExpression> l = elems; l.nonEmpty(); l = l.tail) {
|
||||
buf.append(attributeAnnotationValue(types.elemtype(expectedElementType),
|
||||
l.head,
|
||||
env));
|
||||
|
||||
19
test/langtools/tools/javac/T8320144.java
Normal file
19
test/langtools/tools/javac/T8320144.java
Normal file
@ -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 };
|
||||
}
|
||||
}
|
||||
4
test/langtools/tools/javac/T8320144.out
Normal file
4
test/langtools/tools/javac/T8320144.out
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user