You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/11/11 02:01:05 UTC

[jira] [Closed] (GROOVY-9452) Multiple Repeatable Annotations Container generated if an explicit container is present and an implicit one required

     [ https://issues.apache.org/jira/browse/GROOVY-9452?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-9452.
-----------------------------

> Multiple Repeatable Annotations Container generated if an explicit container is present and an implicit one required
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-9452
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9452
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.8, 3.0.0
>            Reporter: Björn Kautler
>            Assignee: Paul King
>            Priority: Major
>             Fix For: 4.0.0-alpha-1, 3.0.3
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> Given:
>  * an annotation {{A}} with {{String}} {{value}} which is repeatable with container annotation {{As}}
> If you in Java write
> {code:java}
> @A("a")
> @As({
>   @A("c")
>   @A("d")
> }) {code}
> 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
> {code:java}
> @A("a")
> @A("b")
> @As({
>   @A("c")
>   @A("d")
> }) {code}
> you get a compile error saying that this does not work.
> If you in Groovy write
> {code:java}
> @A("a")
> @As([
>   @A("c")
>   @A("d")
> ]) {code}
> 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
> {code:java}
> @A("a")
> @A("b")
> @As([
>   @A("c")
>   @A("d")
> ]) {code}
> 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
> {code:java}
> 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)
>         ...
> {code}
> 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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)