[ 
https://issues.apache.org/jira/browse/GROOVY-10570?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17522880#comment-17522880
 ] 

Eric Milles commented on GROOVY-10570:
--------------------------------------

https://github.com/apache/groovy/pull/1714

Here is how to emulate the serialized data, in case you want to keep moving:
{code:java}
import groovy.transform.*;
import java.lang.annotation.*;

import static java.util.Collections.singletonMap;

@AnnotationCollector(serializeClass=Groovy10570emu.Data.class)
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface Groovy10570emu {
    class Data {
        public static Object[][] value() {
            return new Object[][] {{EqualsAndHashCode.class, 
singletonMap("useCanEqual", Boolean.FALSE)}};
        }
    }
}
{code}

If you are passing no attributes to an annotation, you will need to supply an 
empty map.  There is not much validation in the method that reads the 
multi-dimensional array so you may need a bit of trial and error if you are 
passing complex values.

> AnnotationCollector produces unspecified errors when used in Java
> -----------------------------------------------------------------
>
>                 Key: GROOVY-10570
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10570
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 4.0.1
>            Reporter: Christopher Smith
>            Priority: Minor
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> I have an {{AnnotationCollector}} that refers to some Java classes (type 
> converters). The stub generator has an error generating the stub, so I tried 
> writing the annotation itself in Java. While this compiled correctly, when 
> compiling tests using that annotation I get a BUG! in the Groovy compiler:
> {code}
> BUG! exception in phase 'semantic analysis' in source unit 
> '/home/christopher/git/.../IgnoreMetaClassAttributeConverterProviderTest.groovy'
>  com.example.DynamoDbRecord.value()
> ...
> Caused by: java.lang.NoSuchMethodException: com.example.DynamoDbRecord.value()
>     at java.lang.Class.getMethod (Class.java:2108)
>     at 
> org.codehaus.groovy.transform.AnnotationCollectorTransform.getTargetListFromClass
>  (AnnotationCollectorTransform.java:276)
>     at org.codehaus.groovy.transform.AnnotationCollectorTransform.getMeta 
> (AnnotationCollectorTransform.java:76)
>     at 
> org.codehaus.groovy.transform.AnnotationCollectorTransform.getStoredTargetList
>  (AnnotationCollectorTransform.java:226)
>     at 
> org.codehaus.groovy.transform.AnnotationCollectorTransform.getTargetAnnotationList
>  (AnnotationCollectorTransform.java:356)
>     at org.codehaus.groovy.transform.AnnotationCollectorTransform.visit 
> (AnnotationCollectorTransform.java:383)
>     at 
> org.codehaus.groovy.transform.ASTTransformationCollectorCodeVisitor.findCollectedAnnotations
>  (ASTTransformationCollectorCodeVisitor.java:207)
>     at 
> org.codehaus.groovy.transform.ASTTransformationCollectorCodeVisitor.visitAnnotations
>  (ASTTransformationCollectorCodeVisitor.java:93)
> {code}
> Adding a {{String value default ""}} to the annotation produces an NPE.
> It would make sense to me to learn that using {{AnnotationCollector}} in Java 
> is unsupported, but the Groovy compiler should probably have a better error 
> report.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to