You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/07/05 17:05:00 UTC

[jira] [Updated] (GROOVY-6705) Compiler Doesn't Enforce Required Annotation Attributes

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

Eric Milles updated GROOVY-6705:
--------------------------------
    Labels: annotations breaking  (was: breaking)

> Compiler Doesn't Enforce Required Annotation Attributes
> -------------------------------------------------------
>
>                 Key: GROOVY-6705
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6705
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.1.9
>            Reporter: Jeff Brown
>            Priority: Major
>              Labels: annotations, breaking
>         Attachments: annotation.zip
>
>
> I don't know if this is the same as GROOVY-3454 or not.  That issue is marked resolved but I am seeing the problem with 2.1.9.
> Code from the attached app...
> {code:title=src/main/java/com/demo/MyAnnotation.java|borderStyle=solid}
> package com.demo;
> import java.lang.annotation.ElementType;
> import java.lang.annotation.Retention;
> import java.lang.annotation.RetentionPolicy;
> import java.lang.annotation.Target;
> @Retention(RetentionPolicy.RUNTIME)
> @Target(ElementType.FIELD)
> public @interface MyAnnotation {
>     String value();
>     String code() default "";
> }
> {code}
> {code:title=src/test/groovy/com/demo/MyAnnotationSpec.groovy|borderStyle=solid}
> package com.demo
> class MyAnnotationSpec extends spock.lang.Specification {
>     void 'test code'() {
>         expect:
>         Widget.getDeclaredField('name').getAnnotation(MyAnnotation).code() == 'alpha'
>     }
> }
> class Widget {
>     @MyAnnotation(code='alpha')
>     String name
> }
> {code}
> That test compiles and passes.  I expected the compiler to fail on the Widget class since the annotation does not provide a value for the "value" attribute.
> Am I overlooking something simple or is this broken?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)