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

ASF GitHub Bot commented on GROOVY-11578:
-----------------------------------------

royteeuwen commented on PR #2330:
URL: https://github.com/apache/groovy/pull/2330#issuecomment-3634008318

   @eric-milles yes, it should become available through Service Loading **but** 
there are two issues:
   
   - Now that groovy-json is set as a Fragment, it does not work anymore, only 
Bundles in OSGi will be loaded through service loading, hence the change of 
removing the Fragment-Host property that was initially part of this PR
   - There can be a race condition, where the Bundle is still starting up and 
registering it's service loaders (which happens sort of async), but the 
groovy-json class FastStringUtils is already called, meaning that it doesn't 
find the service loader at that moment. So the code how it's written now is 
never going to work in that case because it only allows you to get the string 
service instance once. I hope this will be resolved in 
https://github.com/apache/felix-dev/pull/455 and 
https://github.com/osgi/osgi/pull/882
   
   I will check if I find some time to add test cases :) I expect it will be a 
simple test hehe. 




> Services loaded via the service loader not working in (some) OSGi contexts 
> for Groovy 4+
> ----------------------------------------------------------------------------------------
>
>                 Key: GROOVY-11578
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11578
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.26
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>         Attachments: groovy-json-example.zip
>
>
> This is related to GROOVY-11570 and GROOVY-11571 but it seems worthwhile 
> having an issue that is just about getting the services working again.
> Current steps to reproduce:
> * clone the apache/karaf repo
> * change groovy versions: codehaus=>apache, 3.0.24=>4.0.26
> * add an additional test to GroovyTest (see below) to exercise service loader 
> related functionality
> * run "mvn test" in the itests directory
> Additional test:
> {code}
> @Test
> public void testExecGroovyJsonCommand() throws Exception {
>     String resultNoArgs = executeCommand("groovy:exec \""
>             + "import org.apache.groovy.json.internal.FastStringUtils\n"
>             + "println FastStringUtils.toCharArray('result') == 
> 'result'.toCharArray()\"");
>     assertContains("true", resultNoArgs);
> }
> {code}
> Result:
> {noformat}
> <system-err><![CDATA[groovy:exec "import 
> org.apache.groovy.json.internal.FastStringUtils
> println FastStringUtils.toCharArray('result') == 'result'.toCharArray()"
> java.lang.RuntimeException: Unable to load FastStringService
>       at 
> org.apache.karaf.itests.KarafTestSupport.executeCommand(KarafTestSupport.java:444)
>       at 
> org.apache.karaf.itests.KarafTestSupport.executeCommand(KarafTestSupport.java:358)
>       at 
> org.apache.karaf.itests.KarafTestSupport.executeCommand(KarafTestSupport.java:345)
>       at 
> org.apache.karaf.itests.GroovyTest.testExecGroovyJsonCommand(GroovyTest.java:54)
>         ...
>       at 
> org.ops4j.pax.exam.invoker.junit.internal.ContainerTestRunner.runChild(ContainerTestRunner.java:43)
>         ...
> Caused by: java.lang.RuntimeException: Unable to load FastStringService
>       at 
> org.apache.groovy.json.internal.FastStringUtils.getService(FastStringUtils.java:56)
>         ...
> {noformat}



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

Reply via email to