Skip to content

8320144: Compilation crashes when a custom annotation with invalid default value is used #1758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ private Attribute attributeAnnotationValue(Type expectedElementType, JCExpressio

if (expectedElementType.hasTag(ARRAY)) {
return getAnnotationArrayValue(expectedElementType, tree, env);

}

//error recovery
Expand Down Expand Up @@ -703,11 +702,15 @@ private Attribute getAnnotationArrayValue(Type expectedElementType, JCExpression
}

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));
Expand Down
19 changes: 19 additions & 0 deletions test/langtools/tools/javac/T8320144.java
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions test/langtools/tools/javac/T8320144.out
Original file line number Diff line number Diff line change
@@ -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