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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 2.6.0-alpha-4, 3.0.0-alpha-3, 2.5.4
    • None
    • class generator
    • 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

        Issue Links

          Activity

            People

              Unassigned Unassigned
              cott@redstonecontentsolutions.com Caleb Ott
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: