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

GroovyShell/Grape cannot use Extension Modules that extend Closure

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.7, 2.3.8, 2.3.9
    • Fix Version/s: 2.3.10, 2.4.0-rc-2
    • Component/s: Grape, Groovysh
    • Labels:
      None
    • Environment:
      Mac OS X 10.10 with Java 8u25
      Ubuntu Server 14.04.1 with Java 7u65

      Description

      Test.groovy
      @Grab('org.elasticsearch:elasticsearch-groovy:1.4.2')
      def printClosure(Closure closure) {
        println closure.asJsonString()
      }
      
      printClosure { field = "simple" }
      

      The extension method's signature is static String asJsonString(Closure self) (https://github.com/elasticsearch/elasticsearch-groovy/blob/v1.4.2/src/main/groovy/org/elasticsearch/groovy/common/xcontent/XContentBuilderExtensions.groovy#L97).

      Output
      $ groovy --indy Test.groovy
      Caught: groovy.lang.MissingMethodException: No signature of method: Test.asJsonString() is applicable for argument types: () values: []
      Possible solutions: toString(), toString()
      groovy.lang.MissingMethodException: No signature of method: Test.asJsonString() is applicable for argument types: () values: []
      Possible solutions: toString(), toString()
      	at Test.printClosure(Test.groovy:3)
      	at Test.run(Test.groovy:6)
      

      Tested on both a Mac and Linux (with and without --indy does not matter):

      • Groovy Version: 2.3.9 JVM: 1.8.0_25 Vendor: Oracle Corporation OS: Mac OS X
      • Groovy Version 2.3.9 JVM: 1.7.0_65 Vendor: Oracle Corporation OS: Linux

      However, if I don't use Grape/the GroovyShell, then the same code works with the same dependencies. I always use Gradle to build my code, so it wasn't until a user pointed this issue out that I became aware of it.

      This relates to GROOVY-6557. On my Mac, I was always able to reproduce GROOVY-6447, but my core issue appears to relate to Closure extension methods across multiple platforms (https://github.com/elasticsearch/elasticsearch-groovy/issues/19).

        Attachments

        1. groovy7225.zip
          4 kB
          Chris Earle

          Issue Links

            Activity

              People

              • Assignee:
                melix C├ędric Champeau
                Reporter:
                pickypg Chris Earle
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: