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

Paul King closed GROOVY-12415.
------------------------------

> Groovy 5 decompiler crashes on TYPE_USE annotation on primitive Java record 
> component
> -------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12415
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12415
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 5.0.8, 5.1.2
>            Reporter: Piotr Boryczko
>            Assignee: Paul King
>            Priority: Major
>             Fix For: 5.1.3
>
>         Attachments: groovy-record-primitive-type-annotation.zip
>
>
> Groovy 5 throws `GroovyBugError` while lazily configuring a decompiled,
> precompiled Java record when a primitive record component carries a
> `TYPE_USE` annotation:
>  
> {code:java}
> Caught: BUG! Adding type annotation @TypeAnnotation to non-redirect node: int
> {code}
> The failure is in *ClassSignatureParser.configureClass*. It unconditionally
> passes the primitive component's *ClassNode* to
> *Annotations.addTypeAnnotations*, which eventually calls
> *ClassNode.addTypeAnnotation*. Shared primitive nodes are not redirect nodes,
> so that method aborts.
> This occurs in ordinary applications through frameworks that inspect or infer
> types from records. Jakarta Validation makes it particularly easy to 
> encounter:
> constraints such as *@Min*, and *@Max* include *TYPE_USE* in their
> targets.
> The attached reproducer does not use Spock, Jakarta Validation, Gradle, or any
> third-party dependency other than Groovy itself.
> h5. Groovy 5 source location
> *org.codehaus.groovy.ast.decompiled.ClassSignatureParser.configureClass*:
> {code:java}
> RecordComponentNode recordComponent =
>         new RecordComponentNode(classNode, rc.name, type[0]);
> Annotations.addAnnotations(rc, recordComponent, resolver);
> Annotations.addTypeAnnotations(rc, type[0], resolver);
> {code}
> Possible narrow fix for Groovy 5
> Guard primitive component types before calling *addTypeAnnotations*:
> {code:java}
> if (!ClassHelper.isPrimitiveType(type[0])) {
>     Annotations.addTypeAnnotations(rc, type[0], resolver);
> }
> {code}
> This guard was tested locally against Groovy 5.0.8: the reproducer fails with
> the original class and succeeds when the patched *ClassSignatureParser* is
> placed first on the compiler classpath.



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

Reply via email to