This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 6e72f5c64d GROOVY-11578: provide default `FastStringService` in case
of service loader failure (#2330)
6e72f5c64d is described below
commit 6e72f5c64d51914f483ba78f4d6e1b990bfbf9a1
Author: Roy Teeuwen <[email protected]>
AuthorDate: Tue Dec 16 15:37:30 2025 +0100
GROOVY-11578: provide default `FastStringService` in case of service loader
failure (#2330)
Co-authored-by: Roy Teeuwen <[email protected]>
---
.../groovy/json/internal/FastStringUtils.java | 2 +-
.../json/internal/FastStringUtilsTest.groovy | 58 ++++++++++++++++++++++
2 files changed, 59 insertions(+), 1 deletion(-)
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 4bf9ef4edd..e05a1ced03 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
@@ -47,7 +47,7 @@ public class FastStringUtils {
}
}
}
- return found;
+ return found != null ? found : new DefaultFastStringService();
}
}
diff --git
a/subprojects/groovy-json/src/test/groovy/org/apache/groovy/json/internal/FastStringUtilsTest.groovy
b/subprojects/groovy-json/src/test/groovy/org/apache/groovy/json/internal/FastStringUtilsTest.groovy
new file mode 100644
index 0000000000..5c5955b82d
--- /dev/null
+++
b/subprojects/groovy-json/src/test/groovy/org/apache/groovy/json/internal/FastStringUtilsTest.groovy
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.groovy.json.internal
+
+import groovy.test.GroovyTestCase
+
+class FastStringUtilsTest extends GroovyTestCase {
+
+ static class NoServiceLoaderGroovyClassLoader extends GroovyClassLoader {
+
+ @Override
+ Enumeration<URL> getResources(String name) throws IOException {
+ if (name ==
"META-INF/services/org.apache.groovy.json.FastStringServiceFactory") {
+ return Collections.emptyEnumeration();
+ }
+ return super.getResources(name);
+ }
+ }
+
+ void testToCharArray() {
+ char[] expected = ["t", "e", "s", "t"]
+ assertEquals(expected, FastStringUtils.toCharArray("test"))
+ }
+
+ void testToCharArrayWithNoServiceLoaderUsedTheDefaultStringService() {
+ ClassLoader previous = Thread.currentThread().getContextClassLoader()
+ try {
+ // Making sure that our class loader is used in the ServiceLoader
class
+ def loader = new NoServiceLoaderGroovyClassLoader();
+ Thread.currentThread().setContextClassLoader(loader)
+ def shell = new GroovyShell(loader)
+ def result = shell.evaluate('''
+ import org.apache.groovy.json.internal.FastStringUtils
+ FastStringUtils.toCharArray("json")
+ ''')
+ assert result == ['j', 's', 'o', 'n'] as char[]
+
+ } finally {
+ Thread.currentThread().setContextClassLoader(previous)
+ }
+ }
+}