[
https://issues.apache.org/jira/browse/GROOVY-12793?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18148261#comment-18148261
]
ASF GitHub Bot commented on GROOVY-12793:
-----------------------------------------
testlens-app[bot] commented on PR #3316:
URL: https://github.com/apache/groovy/pull/3316#issuecomment-7044602899
## 🚨 All tests passed but jobs failed 🚨
### Failed Jobs without Test Failures
❌ [Build and test / lts \(21,
ubuntu-latest\)](https://github.com/apache/groovy/actions/runs/44767403761/job/136395608967?pr=3316)
🏷️ Commit: 0275617e7024b69d0490e26219948989fba25ae7
▶️ Tests: 9515 executed
🟡 Checks: 9/25 completed
### Rerun Controls
Click the checkbox to trigger a rerun:
🔲 **Rerun jobs**
---
_Learn more about TestLens at
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
> SC: a call to a method returning or taking an array of a bounded type
> variable, such as Class#getAnnotationsByType, fails with NoSuchMethodError
> ------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12793
> URL: https://issues.apache.org/jira/browse/GROOVY-12793
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 4.0.33, 5.0.8, 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> A statically compiled call to a JDK method declared with an array of a
> bounded type variable is written with Object[] in the method descriptor, and
> fails at run time:
> {code:groovy}
> @groovy.transform.CompileStatic
> void test() {
> Class<?> type = String
> Deprecated[] annotations = type.getAnnotationsByType(Deprecated)
> }
> test()
> {code}
> {noformat}
> java.lang.NoSuchMethodError: 'java.lang.Object[]
> java.lang.Class.getAnnotationsByType(java.lang.Class)'
> {noformat}
> {{Class#getAnnotationsByType}} is declared {{<A extends Annotation> A[]
> getAnnotationsByType(Class<A>)}}, whose descriptor returns
> {{[Ljava/lang/annotation/Annotation;}}. The same happens for
> {{getDeclaredAnnotationsByType}}, and for any method of a precompiled class
> that returns or takes {{T[]}} or {{T[][]}} with {{T extends X}}, such as
> {{static <T extends Number> T[] array(Class<T>)}}. Reproduced with 4.0.33,
> 5.1.3, 6.0.0, 6.0.1-SNAPSHOT and 7.0.0-SNAPSHOT. Methods of a class compiled
> in the same unit are fine.
> Cause: the JVM descriptor of an array is built from its innermost component
> type ({{TypeUtil.getDescriptionByType}} walks {{getComponentType()}}). For
> {{A[]}} that component is the type-variable placeholder. Only the array node
> is redirected to the erasure; the placeholder keeps {{Object}} as its
> redirect.
> * {{Java8#makeClassNode}}, the reflection path (the predefined types of
> {{ClassHelper}} such as {{java.lang.Class}}, and every class when
> asmResolving is off), never redirects the component, for return and parameter
> types of any dimension.
> * {{TypeSignatureParser#applyErasure}}, the class-file path, redirects the
> component for one dimension only, so {{T[][]}} from a jar is written as
> {{Object[][]}}.
> Fix: redirect every component level of an array of a type variable to the
> matching level of its erasure, in both places.
> Workaround: call the method from dynamic code ({{@CompileDynamic}}) or from
> Java, or use {{getAnnotation}} on the annotation and its container.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)