[
https://issues.apache.org/jira/browse/GROOVY-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18116207#comment-18116207
]
ASF GitHub Bot commented on GROOVY-12415:
-----------------------------------------
paulk-asert opened a new pull request, #2939:
URL: https://github.com/apache/groovy/pull/2939
…rimitive Java record component
A precompiled record component without a generic signature took its type
from getPlainNodeReference(), which returns the shared primitive ClassNode
itself. Adding the component's type annotations to that resolved node threw
"BUG! Adding type annotation ... to non-redirect node: int". Use a fresh
redirect node for primitives too, so the annotation is kept rather than dropped.
> 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
> 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)