Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8905

MissingMethodException when private method is called on parent class in a closure

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.6.0-alpha-4, 3.0.0-alpha-3, 2.5.4
    • Fix Version/s: None
    • Component/s: class generator
    • Labels:
      None

      Description

      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.

      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()
      
      

      Output:

      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)

       

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              cott@redstonecontentsolutions.com Caleb Ott
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: