Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.5.8, 3.0.0
-
None
Description
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.
$ 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();
Attachments
Issue Links
- links to