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

MissingMethodException when a base class calls a private static method inside a closure

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 5.0.0-alpha-1
    • None
    • None

    Description

      A method call inside a closure that targets a base class private method results in a MissingMethodException.

      class Base {
          def baseRun() {
              [1].each {
                  baseRunStatic()
              }
          }
          private static void baseRunStatic() {
              println "baseRunStatic()"
          }
      }
      class StaticTest extends Base {
          def run() {
              baseRun()
          }
      }
      new StaticTest().run()
      

      Try executing the attached script with Groovy 3.0.7. It will yield:

      ❯ groovy test.groovy
      Caught: groovy.lang.MissingMethodException: No signature of method: StaticTest.baseRunStatic() is applicable for argument types: () values: []
      groovy.lang.MissingMethodException: No signature of method: StaticTest.baseRunStatic() is applicable for argument types: () values: []
      	at Base$_baseRun_closure1.doCall(test.groovy:5)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at Base.baseRun(test.groovy:4)
      	at Base$baseRun.callCurrent(Unknown Source)
      	at StaticTest.run(test.groovy:17)
      	at StaticTest$run.call(Unknown Source)
      	at test.run(test.groovy:21)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      

      As a work around the method call to baseRunStatic() can be prefixed with the class name.

      Attachments

        1. test.groovy
          0.3 kB
          Benedikt Ritter

        Issue Links

          Activity

            People

              emilles Eric Milles
              britter Benedikt Ritter
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: