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

groovy-json not working from <groovy> Ant task

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.5.0
    • Fix Version/s: None
    • Component/s: Ant integration, JSON
    • Labels:

      Description

      groovy-json 2.5.X uses java.util.ServiceLoader to load FastStringService and therefore doesn't work in a multi-classloader environment

      build.xml

      <project name="test" default="build" basedir=".">
      
        <taskdef name="groovy" 
                 classname="org.codehaus.groovy.ant.Groovy" 
                 classpath="groovy-2.5.2.jar:groovy-ant-2.5.2.jar:groovy-json-2.5.2.jar"/>
      
        <target name="build">
          <groovy>
          <![CDATA[
            import groovy.json.*
            def json = new JsonSlurper().parseText('{"person":{"name":"Guillaume","age":33,"pets":["dog","cat"]}}')
            println new JsonBuilder(json).toPrettyString()
          ]]>
          </groovy>
        </target>
        
      </project>
      

      Build output:

      BUILD FAILED
      C:\test2\build.xml:8: java.lang.RuntimeException: Unable to load FastStringService
              at org.apache.groovy.json.internal.FastStringUtils.getService(FastStringUtils.java:57)
              at org.apache.groovy.json.internal.FastStringUtils.toCharArray(FastStringUtils.java:67)
              at org.apache.groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:112)
              at groovy.json.JsonSlurper.parseText(JsonSlurper.java:205)
              at groovy.json.JsonSlurper$parseText.call(Unknown Source)
              at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
              at embedded_script_in_C__test2_build_dot_xml.run(embedded_script_in_C__test2_build_dot_xml:2)
              at org.codehaus.groovy.ant.Groovy.parseAndRunScript(Groovy.java:517)
              at org.codehaus.groovy.ant.Groovy.execGroovy(Groovy.java:464)
              at org.codehaus.groovy.ant.Groovy.execute(Groovy.java:322)
              at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
              at org.apache.tools.ant.Task.perform(Task.java:348)
              at org.apache.tools.ant.Target.execute(Target.java:435)
              at org.apache.tools.ant.Target.performTasks(Target.java:456)
              at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
              at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
              at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
              at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
              at org.apache.tools.ant.Main.runBuild(Main.java:851)
              at org.apache.tools.ant.Main.startAnt(Main.java:235)
              at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
              at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
      

        Attachments

        1. testsuite.7z
          6.88 MB
          Gregory Moltchadski

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              greg2001 Gregory Moltchadski
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: