[
https://issues.apache.org/jira/browse/GROOVY-9987?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles updated GROOVY-9987:
--------------------------------
Description:
A method call inside a closure that targets a base class private method results
in a {{MissingMethodException}}.
{code:groovy}
class Base {
def baseRun() {
[1].each {
baseRunStatic()
}
}
private static void baseRunStatic() {
println "baseRunStatic()"
}
}
class StaticTest extends Base {
def run() {
baseRun()
}
}
new StaticTest().run()
{code}
Try executing the attached script with Groovy 3.0.7. It will yield:
{code}
❯ groovy test.groovy
Caught: groovy.lang.MissingMethodException: No signature of method:
StaticTest.baseRunStatic() is applicable for argument types: () values: []
groovy.lang.MissingMethodException: No signature of method:
StaticTest.baseRunStatic() is applicable for argument types: () values: []
at Base$_baseRun_closure1.doCall(test.groovy:5)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at Base.baseRun(test.groovy:4)
at Base$baseRun.callCurrent(Unknown Source)
at StaticTest.run(test.groovy:17)
at StaticTest$run.call(Unknown Source)
at test.run(test.groovy:21)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
{code}
As a work around the method call to baseRunStatic() can be prefixed with the
class name.
was:
If a class calls a method on a base class and that method class a static method
inside a closure a MissingMethodException will be thrown at runtime.
{code:groovy}
class Base {
def baseRun() {
[1].each {
baseRunStatic()
}
}
private static void baseRunStatic() {
println "baseRunStatic()"
}
}
class StaticTest extends Base {
def run() {
baseRun()
}
}
new StaticTest().run()
{code}
Try executing the attached script with Groovy 3.0.7. It will yield:
{code}
❯ groovy test.groovy
Caught: groovy.lang.MissingMethodException: No signature of method:
StaticTest.baseRunStatic() is applicable for argument types: () values: []
groovy.lang.MissingMethodException: No signature of method:
StaticTest.baseRunStatic() is applicable for argument types: () values: []
at Base$_baseRun_closure1.doCall(test.groovy:5)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at Base.baseRun(test.groovy:4)
at Base$baseRun.callCurrent(Unknown Source)
at StaticTest.run(test.groovy:17)
at StaticTest$run.call(Unknown Source)
at test.run(test.groovy:21)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
{code}
As a work around the method call to baseRunStatic() can be prefixed with the
class name.
> MissingMethodException when a base class calls a private static method inside
> a closure
> ----------------------------------------------------------------------------------------
>
> Key: GROOVY-9987
> URL: https://issues.apache.org/jira/browse/GROOVY-9987
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 3.0.7
> Reporter: Benedikt Ritter
> Priority: Major
> Attachments: test.groovy
>
>
> A method call inside a closure that targets a base class private method
> results in a {{MissingMethodException}}.
> {code:groovy}
> class Base {
> def baseRun() {
> [1].each {
> baseRunStatic()
> }
> }
> private static void baseRunStatic() {
> println "baseRunStatic()"
> }
> }
> class StaticTest extends Base {
> def run() {
> baseRun()
> }
> }
> new StaticTest().run()
> {code}
> Try executing the attached script with Groovy 3.0.7. It will yield:
> {code}
> ❯ groovy test.groovy
> Caught: groovy.lang.MissingMethodException: No signature of method:
> StaticTest.baseRunStatic() is applicable for argument types: () values: []
> groovy.lang.MissingMethodException: No signature of method:
> StaticTest.baseRunStatic() is applicable for argument types: () values: []
> at Base$_baseRun_closure1.doCall(test.groovy:5)
> at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at Base.baseRun(test.groovy:4)
> at Base$baseRun.callCurrent(Unknown Source)
> at StaticTest.run(test.groovy:17)
> at StaticTest$run.call(Unknown Source)
> at test.run(test.groovy:21)
> at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> {code}
> As a work around the method call to baseRunStatic() can be prefixed with the
> class name.
--
This message was sent by Atlassian Jira
(v8.20.7#820007)