[ 
https://issues.apache.org/jira/browse/GROOVY-8905?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King closed GROOVY-8905.
-----------------------------

> 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.20.1#820001)

Reply via email to