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

Calling a static method in a closure from another static method fails to find the static method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.0-JSR-6
    • 1.0
    • class generator
    • None
    • Fails in both scripts and classes

    Description

      While it's possible to call static methods from other static methods in the same class, as shown in the next example:

      groovy> static foo()

      { println "foo" }
      groovy> static bar() { foo() }
      groovy> bar()
      groovy> go
      foo

      but if we're inside a closure in a static method, we can't call other static methods. The following example illustrates the problem:

      groovy> static foo() { println "foo" }

      groovy> static bar() { 1.times

      { foo() }

      }
      groovy> bar()
      groovy> go
      Caught: groovy.lang.MissingMethodException: No signature of method CommandLine$_bar_closure1.foo() is applicable for argument types: () values: {}
      at CommandLine$_bar_closure1.doCall(CommandLine.groovy:2)
      at gjdk.java.lang.Number_GroovyReflector.invoke(Unknown Source)
      at CommandLine.bar(CommandLine.groovy:2)
      at gjdk.CommandLine_GroovyReflector.invoke(Unknown Source)
      at CommandLine.run(CommandLine.groovy:3)

      Ooops

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            guillaume Guillaume Sauthier
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: