Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.5.8, 3.0.0
-
None
-
None
Description
Given:
- an annotation A with String value which is repeatable with container annotation As
If you in Java write
@A("a") @As({ @A("c") @A("d") })
this is transported 1:1 to the byte code and if you use getAnnotationsByType(A.class) you properly get all three annotations.
If you in Java write
@A("a") @A("b") @As({ @A("c") @A("d") })
you get a compile error saying that this does not work.
If you in Groovy write
@A("a") @As([ @A("c") @A("d") ])
this is transported 1:1 to the byte code and if you use getAnnotationsByType(A.class) you properly get all three annotations.
All ok.
But now comes the issue.
If you in Groovy write
@A("a") @A("b") @As([ @A("c") @A("d") ])
you end up with two @As annotations in the final class file.
If you then try to read annotations for example at runtime, you get
java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface As: @As(value=[@A(value="a"), @A(value="b")]) at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:125) at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) at java.lang.reflect.Executable.declaredAnnotations(Executable.java:599) at java.lang.reflect.Executable.declaredAnnotations(Executable.java:597) at java.lang.reflect.Executable.getAnnotation(Executable.java:570) at java.lang.reflect.Method.getAnnotation(Method.java:622) ...
So the Groovy compiler should probably also refuse to go on if there are mutliple single instances of a repeatable annotation if the respective container annotation is already present.
Attachments
Issue Links
- links to