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/04/15 14:04:00 UTC

[jira] [Commented] (GROOVY-10570) AnnotationCollector produces unspecified errors when used in Java

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

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

{{@AnnotationCollector}} requires the use of the AST transform to work.  If you wanted to write the annotation in java, you would need to recreate the storage mechanism that the transform relies on.  This is a {{serializeClass}} attribute in legacy scenarios and an inner class "AnnoType$CollectorHelper" in more recent releases.  You could probably reverse engineer it from a compiled meta-annotation, but the details are probably not considered API.

In GROOVY-10571 you have Java depends on Groovy depends on Java.  This bi-directional dependency is supported in many cases, but there are some edge cases, like class literals, that can be difficult to work out before resolving either Java or Groovy types.  Eclipse has a different mechanism from the stub generation to support these types of relationships.  You can try out the {{groovy-eclipse-batch}} compiler as an alternative to {{groovyc}} for Ant/Maven/... builds.

> 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
>
> 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)