You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Brad Beck (Jira)" <ji...@apache.org> on 2020/03/19 13:59:00 UTC

[jira] [Created] (GROOVY-9477) FastStringServiceFactory SPI loading in OSGi

Brad Beck created GROOVY-9477:
---------------------------------

             Summary: FastStringServiceFactory SPI loading in OSGi
                 Key: GROOVY-9477
                 URL: https://issues.apache.org/jira/browse/GROOVY-9477
             Project: Groovy
          Issue Type: Bug
          Components: JSON
    Affects Versions: 2.5.8
            Reporter: Brad Beck


I think I may have come across a bug in how {{FastStringUtils.ServiceHolder}} does service loading of {{FastStringServiceFactory}} in OSGi enviroments for groovy-json 2.5+.

I put together some Pax Exam tests that I believe exhibit the problem.
https://github.com/bradbeck/spitest

The tests with {{Fail}} in the name fail with current release, whereas the tests with {{Pass}} in the name currently pass. The difference is only the order in which the test methods are executed.

I have confirmed (with the help of @ataylor284) that making a small change in FastStringUtils allows SpiFly to correctly intercept the service loading in OSGi environments. This allows the above set of tests to all pass.

That change (relative to GROOVY_3_0_X) is as follows.
{code}
$ git diff
diff --git a/subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/FastStringUtils.java b/subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/FastStringUtils.java
index a8c5dc6fe1..4bf9ef4edd 100644
--- a/subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/FastStringUtils.java
+++ b/subprojects/groovy-json/src/main/java/org/apache/groovy/json/internal/FastStringUtils.java
@@ -33,11 +33,10 @@ public class FastStringUtils {
         static final FastStringService INSTANCE = loadService();
         private static FastStringService loadService() {
-            ClassLoader loader = Thread.currentThread().getContextClassLoader();
 // left classloading very simple in light of potential changes needed for jdk9
 // that means you might need @GrabConfig(systemClassLoader=true) if getting json via grab
 //            ClassLoader rootLoader = DefaultGroovyMethods.getRootLoader(loader);
-            ServiceLoader<FastStringServiceFactory> serviceLoader = ServiceLoader.load(FastStringServiceFactory.class, loader);
+            ServiceLoader<FastStringServiceFactory> serviceLoader = ServiceLoader.load(FastStringServiceFactory.class);
             FastStringService found = null;
             for (FastStringServiceFactory factory : serviceLoader) {
                 FastStringService service = factory.getService();
{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)