You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/04/08 14:51:00 UTC
[jira] [Comment Edited] (GROOVY-8905) MissingMethodException when
private method is called on parent class in a closure
[ https://issues.apache.org/jira/browse/GROOVY-8905?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17303708#comment-17303708 ]
Eric Milles edited comment on GROOVY-8905 at 4/8/21, 2:50 PM:
--------------------------------------------------------------
See also GROOVY-9987, GROOVY-7375, GROOVY-6335, GROOVY-5438, GROOVY-5051 and GROOVY-2433
If {{theSomething()}} was protected there would be no issue. You can also mark {{doSomethingParent()}} with {{@CompileStatic}} to trigger bridge method generation for the private member accesses inside closures (or inner classes).
was (Author: emilles):
See also GROOVY-9987, GROOVY-6335, GROOVY-5438, GROOVY-5051 and GROOVY-2433
If {{theSomething()}} was protected there would be no issue. You can also mark {{doSomethingParent()}} with {{@CompileStatic}} to trigger bridge method generation for the private member accesses inside closures (or inner classes).
> MissingMethodException when private method is called on parent class in a closure
> ---------------------------------------------------------------------------------
>
> Key: GROOVY-8905
> URL: https://issues.apache.org/jira/browse/GROOVY-8905
> Project: Groovy
> Issue Type: Bug
> Components: class generator
> Affects Versions: 2.6.0-alpha-4, 3.0.0-alpha-3, 2.5.4
> Reporter: Caleb Ott
> Priority: Major
>
> This appears to be a bug since a MissingMethodException is being thrown when it shouldn't be.
> Here is the simplified code to reproduce the issue. I've tested on 2.5.4/2.6.0-alpha-4/3.0.0-alpha-3.
> {code:java}
> class Parent {
> protected void doSomethingParent() {
> // calling it outside of the closure works fine
> theSomething(1_000, 'This works')
> // setup a closure that calls another private method in the parent
> Closure closure = { int num ->
> // calling it inside the closure breaks
> theSomething(num, 'this breaks')
> }
> closure(10)
> }
> // only breaks because it is "private"
> private void theSomething(int num, String someValue) {
> println "${num} = ${someValue}"
> }
> }
> class Child extends Parent {
> void doSomethingChild() {
> // just calls the parent method
> doSomethingParent()
> }
> }
> // run the test
> def test = new Child()
> test.doSomethingChild()
> {code}
> Output:
> {noformat}
> 1000 = This works
> Caught: groovy.lang.MissingMethodException: No signature of method: Child.theSomething() is applicable for argument types: (Integer, String) values: [10, this breaks]
> groovy.lang.MissingMethodException: No signature of method: Child.theSomething() is applicable for argument types: (Integer, String) values: [10, this breaks]
> at Parent$_doSomethingParent_closure1.doCall(ScratchPad.groovy:10)
> at Parent.doSomethingParent(ScratchPad.groovy:13)
> at Child.doSomethingChild(ScratchPad.groovy:25)
> at Child$doSomethingChild.call(Unknown Source)
> at ScratchPad.run(ScratchPad.groovy:31){noformat}
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)