[
https://issues.apache.org/jira/browse/GROOVY-12570?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18134523#comment-18134523
]
ASF GitHub Bot commented on GROOVY-12570:
-----------------------------------------
codeconsole opened a new pull request, #3099:
URL: https://github.com/apache/groovy/pull/3099
A class that declares `m()` and calls `super.m()`, where `m()` is
package-private in a superclass with the same package name but defined by
another class loader (for example a class of an earlier parse of the same
`GroovyShell`), failed with `MissingMethodException`. The JVM does not let the
subclass method override a package-private method of another run-time package,
so no `super$` method can call it; without one, the meta-class removed the
subclass method from the methods for super calls and kept nothing, as the
superclass method had already been replaced by the subclass method in the index.
The meta-class now keeps the superclass method for super calls in that case.
Invoked reflectively it is the superclass method, because the JVM does not
consider it overridden. Super calls that a `super$` method serves, and
package-private methods of another package, are unchanged.
This needs #3097, which stops generating a `super$` method for a
package-private method of another run-time package and routes the statically
compiled call through the meta-class; its commits are included until it is
merged. It touches the same lines of `MetaClassImpl` as #3048, so whichever is
merged second needs a rebase.
## Tests
`bugs.Groovy12568.testSuperCallOfPackagePrivateMethodOfClassOfAnotherClassLoaderWithMethodOfSameName`
(marked `// GROOVY-12570`), dynamic and `@CompileStatic`, with and without
invokedynamic; it fails without the change.
`bugs`, `groovy.ThisAndSuperTest`, `groovy.lang.*` and
`StaticCompileRuntimePackageTest` pass (1,144 tests), as do the Checkstyle and
CodeNarc gates.
> super.m() cannot reach a package-private method of a superclass defined by
> another class loader
> -----------------------------------------------------------------------------------------------
>
> Key: GROOVY-12570
> URL: https://issues.apache.org/jira/browse/GROOVY-12570
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> def shell = new GroovyShell()
> shell.evaluate '''package p
> class M { @groovy.transform.PackageScope String pm() { 'M' } }
> true
> '''
> shell.evaluate '''package p
> class B extends M { // same package name as M, but another class loader
> String pm() { 'B>' + super.pm() }
> }
> new B().pm()
> ''' // MissingMethodException; expected 'B>M'
> {code}
> The JVM does not let {{B.pm()}} override a package-private method of another
> run-time package, so no {{super$}} method can call it, and the meta-class
> drops the method from the methods for super calls without keeping the
> superclass method. The same holds under {{@CompileStatic}}. Expected:
> {{super.pm()}} calls {{M.pm()}}.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)