Details
-
New Feature
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
-
groovy 2.4.11
Description
raised on stackoverflow: https://stackoverflow.com/questions/44532632/is-the-repeatable-annotation-not-supported-by-groovy/44628119#44628119
Problem: the following code in groovy 2.4.11 / java8
@MyAnnotation(value = "val1") @MyAnnotation(value = "val2") void annotatedMethod() { println("annotated method called") }
should be compiled to this:
@MyAnnotationArray({@MyAnnotation("val1"), @MyAnnotation("val2")}) void annotatedMethod() { println("annotated method called") }
but actually compiled to this:
@MyAnnotation(value = "val1") @MyAnnotation(value = "val2") void annotatedMethod() { println("annotated method called") }
The full groovy script to reproduce problem is below.
It throws exception:
java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface MyAnnotation: @MyAnnotation(value=val2)
at line `List annos = m.getAnnotations()`
import java.lang.annotation.* class MyClass { @MyAnnotation(value = "val1") @MyAnnotation(value = "val2") //change annotation to next line and the code will work //@MyAnnotationArray( [@MyAnnotation("val1"), @MyAnnotation("val2")] ) public void annotatedMethod() { System.out.println("annotated method called"); } public static void main(String... args) { MyClass ob = new MyClass() ob.annotatedMethod() java.lang.reflect.Method m = ob.getClass().getMethod("annotatedMethod") List annos = m.getAnnotations() println("annos = $annos") } } @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @Repeatable(MyAnnotationArray) public @interface MyAnnotation { String value() default "val0"; } @Retention(RetentionPolicy.RUNTIME) public @interface MyAnnotationArray { MyAnnotation[] value() }
Attachments
Issue Links
- is cloned by
-
GROOVY-8236 Report more meaningful error for versions of Groovy not supporting @Repeatable
- Closed
-
GROOVY-8559 CLONE - Add @Repeatable java8 annotation support
- Closed
- links to