Leonard Brünings created GROOVY-10723:
-----------------------------------------
Summary: Closure in parent class can't access private method in
same class when called from a child class
Key: GROOVY-10723
URL: https://issues.apache.org/jira/browse/GROOVY-10723
Project: Groovy
Issue Type: Bug
Affects Versions: 4.0.4, 3.0.12, 2.5.18
Reporter: Leonard Brünings
Private method of parent class can't be accessed by closure when called from a
child class:
{code:groovy}
class Child extends BaseClass {
static void main(String... args) {
println new Child().doStuff([1,2])
}
}
class BaseClass {
private int helper(int a) {
a + 1
}
def doStuff(List<Integer> numbers) {
numbers.collect {
helper(it)
}
}
}
{code}
[WebConsole|https://gwc-experiment.appspot.com/?g=groovy_2_5&codez=eJxdjsEOgjAMhs_yFD1u0SzBs_EgJxNvHI2HuRVYMgbZCpoY3t2BENH_0DRt831VVoYAWWWsBnwSOh3gJANm0_yVQEwgSUZB3xgNtTSO5eSNK4UQIH0Z-Hw2po0Lsg4cPj5QxoVucuqKgl3T3f7Gp9MhGZJETYp_WST0khAiByq0LXo2tnJtkbCFdAaNdSoaC1hUFxPocHaEJfojuK6-o__5cx4J1ViLilYb2CxW4gv6a4qPwypv8mpZJQ]
{noformat}
org.codehaus.groovy.runtime.InvokerInvocationException:
groovy.lang.MissingMethodException: No signature of method: Child.helper() is
applicable for argument types: (Integer) values: [1]
Possible solutions: sleep(long), every(), grep(), every(groovy.lang.Closure),
sleep(long, groovy.lang.Closure)
at BaseClass.invokeMethod(Script1.groovy)
Caused by: groovy.lang.MissingMethodException: No signature of method:
Child.helper() is applicable for argument types: (Integer) values: [1]
Possible solutions: sleep(long), every(), grep(), every(groovy.lang.Closure),
sleep(long, groovy.lang.Closure)
at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:70)
{noformat}
When using a classical foreach loop it works
{code:groovy}
class Child extends BaseClass {
static void main(String... args) {
println new Child().doStuff([1,2])
}
}
class BaseClass {
private int helper(int a) {
a + 1
}
def doStuff(List<Integer> numbers) {
def result = []
for (int it in numbers){
result << helper(it)
}
result
}
}
{code}
[WebConsole|https://gwc-experiment.appspot.com/?g=groovy_2_5&codez=eJxdj0HLwjAMhs_rr3iPG58M9Dy_g54Ebx7FQ12zWaidtJkKsv9uV2dRQwghffK-aW2k91iftFGgO5NVHivpaR3nD4EQniXrGtdOK5yltvmOnbZtWZaQrvXFhI1xCQ9sLCzdXqJ5Uapux33T5Pv5bHEoIjqIQYg6WvyaBYWrZELQwYnMhVw-tvLTReIP80lorLEoavC22mrP1cYyteT-YfvzkdzXnSPsyPeGscT-kOZN5xD9dEibNh8iy7KJr6p0FxdpcUjdC3t_8wkVgmVH]
Removing the {{private}} modifier also fixes this problem.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)