[
https://issues.apache.org/jira/browse/GROOVY-12458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18130151#comment-18130151
]
ASF GitHub Bot commented on GROOVY-12458:
-----------------------------------------
codecov-commenter commented on PR #3004:
URL: https://github.com/apache/groovy/pull/3004#issuecomment-6333971950
##
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/3004?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
Report
:x: Patch coverage is `0%` with `4 lines` in your changes missing coverage.
Please review.
:white_check_mark: Project coverage is 72.4313%. Comparing base
([`7a6f67f`](https://app.codecov.io/gh/apache/groovy/commit/7a6f67fc6121965ea27850486014bf946df887d8?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
to head
([`f759add`](https://app.codecov.io/gh/apache/groovy/commit/f759adddb1bdf373219cc85fd3989d381b151285?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing
lines](https://app.codecov.io/gh/apache/groovy/pull/3004?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
| Patch % | Lines |
|---|---|---|
|
[...y/src/main/groovy/groovy/grape/ivy/GrapeIvy.groovy](https://app.codecov.io/gh/apache/groovy/pull/3004?src=pr&el=tree&filepath=subprojects%2Fgroovy-grape-ivy%2Fsrc%2Fmain%2Fgroovy%2Fgroovy%2Fgrape%2Fivy%2FGrapeIvy.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWdyYXBlLWl2eS9zcmMvbWFpbi9ncm9vdnkvZ3Jvb3Z5L2dyYXBlL2l2eS9HcmFwZUl2eS5ncm9vdnk=)
| 0.0000% | [1 Missing and 1 partial :warning:
](https://app.codecov.io/gh/apache/groovy/pull/3004?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
|
|
[...c/main/groovy/groovy/grape/maven/GrapeMaven.groovy](https://app.codecov.io/gh/apache/groovy/pull/3004?src=pr&el=tree&filepath=subprojects%2Fgroovy-grape-maven%2Fsrc%2Fmain%2Fgroovy%2Fgroovy%2Fgrape%2Fmaven%2FGrapeMaven.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWdyYXBlLW1hdmVuL3NyYy9tYWluL2dyb292eS9ncm9vdnkvZ3JhcGUvbWF2ZW4vR3JhcGVNYXZlbi5ncm9vdnk=)
| 0.0000% | [2 Missing :warning:
](https://app.codecov.io/gh/apache/groovy/pull/3004?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
|
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/groovy/pull/3004?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #3004 +/- ##
==================================================
- Coverage 72.4340% 72.4313% -0.0027%
Complexity 40650 40650
==================================================
Files 1643 1643
Lines 142792 142796 +4
Branches 26844 26846 +2
==================================================
- Hits 103430 103429 -1
- Misses 29822 29825 +3
- Partials 9540 9542 +2
```
| [Files with missing
lines](https://app.codecov.io/gh/apache/groovy/pull/3004?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
| Coverage Δ | |
|---|---|---|
|
[...y/src/main/groovy/groovy/grape/ivy/GrapeIvy.groovy](https://app.codecov.io/gh/apache/groovy/pull/3004?src=pr&el=tree&filepath=subprojects%2Fgroovy-grape-ivy%2Fsrc%2Fmain%2Fgroovy%2Fgroovy%2Fgrape%2Fivy%2FGrapeIvy.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWdyYXBlLWl2eS9zcmMvbWFpbi9ncm9vdnkvZ3Jvb3Z5L2dyYXBlL2l2eS9HcmFwZUl2eS5ncm9vdnk=)
| `33.8308% <0.0000%> (-0.1692%)` | :arrow_down: |
|
[...c/main/groovy/groovy/grape/maven/GrapeMaven.groovy](https://app.codecov.io/gh/apache/groovy/pull/3004?src=pr&el=tree&filepath=subprojects%2Fgroovy-grape-maven%2Fsrc%2Fmain%2Fgroovy%2Fgroovy%2Fgrape%2Fmaven%2FGrapeMaven.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWdyYXBlLW1hdmVuL3NyYy9tYWluL2dyb292eS9ncm9vdnkvZ3JhcGUvbWF2ZW4vR3JhcGVNYXZlbi5ncm9vdnk=)
| `0.0000% <0.0000%> (ø)` | |
... and [7 files with indirect coverage
changes](https://app.codecov.io/gh/apache/groovy/pull/3004/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test
Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests,
report on failures, and find test suite problems.
- :package: [JS Bundle
Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save
yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
> @Grab in a class defined by a non-GroovyClassLoader fails at runtime with
> groovy-grape-maven ("No suitable ClassLoader found for grab")
> ---------------------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12458
> URL: https://issues.apache.org/jira/browse/GROOVY-12458
> Project: Groovy
> Issue Type: Bug
> Components: Grape
> Affects Versions: 6.0.0
> Reporter: Jex Jexler
> Priority: Major
> Attachments: GrabClassLoaderRepro.groovy
>
>
> Since Groovy 6, the static initializer generated for @Grab passes the class's
> own class loader to Grape.grab()
> (GrabAnnotationTransformation.callGrabAsStaticInitIfNeeded: classLoader:
> <Class>.getClassLoader()).
> If that class was defined by a class loader that is not a GroovyClassLoader
> (or RootLoader), but has one as an ancestor, both engines reject the passed
> loader in chooseClassLoader() without considering its parents, and fall back
> to the stack walk via calleeDepth, which (as the comment in
> callGrabAsStaticInitIfNeeded notes) overshoots from a static initializer:
> * GrapeMaven.chooseClassLoader() then throws "RuntimeException: No suitable
> ClassLoader found for grab".
> * GrapeIvy.chooseClassLoader() usually recovers via its fallbacks (scanning
> frames at calleeDepth +/- 2, which finds a class whose class loader has a
> valid ancestor), i.e. more by chance than by design.
> Hosts that define compiled script classes with their own class loaders below
> a GroovyClassLoader are affected. We hit this with *Grengine*
> (https://grengine.ch/), where @Grab works with groovy-grape-ivy, but fails
> with groovy-grape-maven. Grengine now works around it in its GrapeEngine
> wrapper by replacing the passed class loader with its closest valid ancestor:
> https://github.com/alainstalder/grengine/commit/bd0dd9845440f627e282c4b474f1ec111b6f9a5d
> (code:
> https://github.com/alainstalder/grengine/blob/bd0dd9845440f627e282c4b474f1ec111b6f9a5d/src/main/java/ch/grengine/code/groovy/DefaultGroovyCompiler.java#L673-L699)
> *Standalone reproducer (attached, GrabClassLoaderRepro.groovy):* compiles a
> script with @Grab using a GroovyClassLoader, defines the resulting class with
> a plain ClassLoader subclass whose parent is that GroovyClassLoader, and
> instantiates it, which runs the static initializer:
> * with groovy-6.0.0 + groovy-grape-ivy (and its dependencies) on the
> classpath: OK
> * with groovy-6.0.0 + groovy-grape-maven (and its dependencies) on the
> classpath:
> ExceptionInInitializerError, caused by RuntimeException: No suitable
> ClassLoader found for grab
> at groovy.grape.maven.GrapeMaven.chooseClassLoader(GrapeMaven.groovy:785)
> Run e.g. with: java -cp <classpath> groovy.ui.GroovyMain
> GrabClassLoaderRepro.groovy
> *Suggested fix:* in chooseClassLoader() (in both engines, or at least in
> GrapeMaven), if args.classLoader is set but not a valid target, walk up its
> parents to the first valid one before falling back to the stack walk, e.g.:
>
> {code:java}
> ClassLoader loader = (ClassLoader) args.classLoader
> while (loader && !isValidTargetClassLoader(loader)) {
> loader = loader.getParent()
> }
> if (!isValidTargetClassLoader(loader)) {
> // existing stack walk (and fallbacks)
> }{code}
>
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)