[ 
https://issues.apache.org/jira/browse/GROOVY-8792?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17712741#comment-17712741
 ] 

Paul King commented on GROOVY-8792:
-----------------------------------

[~emilles] GROOVY-10881 fixed an issue with groovy-json and OSGi that only 
affected Groovy 4. There might be a remaining issue for OSGi which is covered 
by GROOVY-11000.

To be honest, we'd need further information here to understand whether there is 
more we could do outside OSGi. For JDK8, folks could be trying to use 
groovy-json-direct. In a multi-classloader environment, I can see where 
problems might occur - hence the context classloader workaround mentioned 
above. For JDK11+, folks should not be using groovy-json-direct since the JDK 
doesn't support that performance hack in a JPMS world. If folks aren't trying 
to use groovy-json-direct, I am unsure where a problem might exist unless they 
are trying to create their own uber groovy jar and not bringing across the 
META-INF/services metadata. The groovy-json-direct module doesn't exist for 
Groovy3+. For Groovy3+, we still provide the services hook but only provide the 
default which is in the same jar, so should not lead to classloader issues 
unless folks are indeed using the hook for their own implementation. Perhaps 
for Groovy 5, we should get rid of the hook altogether.

> groovy-json not working from <groovy> Ant task
> ----------------------------------------------
>
>                 Key: GROOVY-8792
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8792
>             Project: Groovy
>          Issue Type: Bug
>          Components: Ant integration, JSON
>    Affects Versions: 2.5.0
>            Reporter: Gregory Moltchadski
>            Priority: Major
>              Labels: ant, json
>         Attachments: testsuite.7z
>
>
> groovy-json 2.5.X uses java.util.ServiceLoader to load FastStringService and 
> therefore doesn't work in a multi-classloader environment
> build.xml
> {code: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>
> {code}
> Build output:
> {code:xml}
> 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)
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to