diff --git a/core-api/src/main/java/com/optimizely/ab/config/parser/DefaultConfigParser.java b/core-api/src/main/java/com/optimizely/ab/config/parser/DefaultConfigParser.java
index ff1748cb0..30a568ae1 100644
--- a/core-api/src/main/java/com/optimizely/ab/config/parser/DefaultConfigParser.java
+++ b/core-api/src/main/java/com/optimizely/ab/config/parser/DefaultConfigParser.java
@@ -16,6 +16,7 @@
*/
package com.optimizely.ab.config.parser;
+import com.optimizely.ab.internal.JsonLibraryDetector;
import com.optimizely.ab.internal.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -70,13 +71,12 @@ ConfigParser get() {
return supplier.get();
}
+ String getClassName() {
+ return className;
+ }
+
private boolean isPresent() {
- try {
- Class.forName(className);
- return true;
- } catch (ClassNotFoundException e) {
- return false;
- }
+ return JsonLibraryDetector.isPresent(className);
}
}
/**
diff --git a/core-api/src/main/java/com/optimizely/ab/event/internal/serializer/DefaultJsonSerializer.java b/core-api/src/main/java/com/optimizely/ab/event/internal/serializer/DefaultJsonSerializer.java
index a914f3e90..d087b76d9 100644
--- a/core-api/src/main/java/com/optimizely/ab/event/internal/serializer/DefaultJsonSerializer.java
+++ b/core-api/src/main/java/com/optimizely/ab/event/internal/serializer/DefaultJsonSerializer.java
@@ -20,6 +20,7 @@
import org.slf4j.LoggerFactory;
import com.optimizely.ab.config.parser.MissingJsonParserException;
+import com.optimizely.ab.internal.JsonLibraryDetector;
import javax.annotation.Nonnull;
@@ -67,12 +68,7 @@ Serializer create() {
}
private static boolean isPresent(@Nonnull String className) {
- try {
- Class.forName(className);
- return true;
- } catch (ClassNotFoundException e) {
- return false;
- }
+ return JsonLibraryDetector.isPresent(className);
}
//======== Lazy-init Holder ========//
diff --git a/core-api/src/main/java/com/optimizely/ab/internal/JsonLibraryDetector.java b/core-api/src/main/java/com/optimizely/ab/internal/JsonLibraryDetector.java
new file mode 100644
index 000000000..4900527ac
--- /dev/null
+++ b/core-api/src/main/java/com/optimizely/ab/internal/JsonLibraryDetector.java
@@ -0,0 +1,69 @@
+/**
+ * Copyright 2026, Optimizely Inc. and contributors
+ *
+ * Licensed 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 com.optimizely.ab.internal;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Detects whether a supported JSON library is available on the classpath.
+ *
+ * Class names are only ever looked up if they are in a fixed allowlist of known JSON library classes, so
+ * {@code Class.forName} can never be driven by an arbitrary (for example user-supplied) class name.
+ * Classes are also loaded without being initialized, so no static initializer of the probed class runs.
+ */
+public final class JsonLibraryDetector {
+
+ private static final Set ALLOWED_CLASS_NAMES = Collections.unmodifiableSet(new HashSet(Arrays.asList(
+ "com.google.gson.Gson",
+ "com.fasterxml.jackson.databind.ObjectMapper",
+ "org.json.JSONObject",
+ "org.json.simple.JSONObject"
+ )));
+
+ private JsonLibraryDetector() {
+ }
+
+ /**
+ * @param className fully qualified class name to check
+ * @return true if the class name is in the allowlist of supported JSON library classes
+ */
+ public static boolean isAllowed(String className) {
+ return className != null && ALLOWED_CLASS_NAMES.contains(className);
+ }
+
+ /**
+ * @param className fully qualified class name to look for
+ * @return true if the class is one of the supported JSON library classes and is present on the classpath,
+ * false if it is absent or is not in the allowlist
+ */
+ public static boolean isPresent(String className) {
+ if (!isAllowed(className)) {
+ return false;
+ }
+
+ try {
+ // className is validated against the fixed allowlist above and the class is not initialized.
+ // nosemgrep: java.lang.security.audit.unsafe-reflection.unsafe-reflection
+ Class.forName(className, false, JsonLibraryDetector.class.getClassLoader());
+ return true;
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+ }
+}
diff --git a/core-api/src/main/java/com/optimizely/ab/internal/JsonParserProvider.java b/core-api/src/main/java/com/optimizely/ab/internal/JsonParserProvider.java
index 8bde2ac66..a93f47bf3 100644
--- a/core-api/src/main/java/com/optimizely/ab/internal/JsonParserProvider.java
+++ b/core-api/src/main/java/com/optimizely/ab/internal/JsonParserProvider.java
@@ -33,13 +33,12 @@ public enum JsonParserProvider {
this.className = className;
}
+ String getClassName() {
+ return className;
+ }
+
private boolean isAvailable() {
- try {
- Class.forName(className);
- return true;
- } catch (ClassNotFoundException e) {
- return false;
- }
+ return JsonLibraryDetector.isPresent(className);
}
public static JsonParserProvider getDefaultParser() {
diff --git a/core-api/src/test/java/com/optimizely/ab/config/parser/ConfigParserSupplierTest.java b/core-api/src/test/java/com/optimizely/ab/config/parser/ConfigParserSupplierTest.java
new file mode 100644
index 000000000..27c082c6d
--- /dev/null
+++ b/core-api/src/test/java/com/optimizely/ab/config/parser/ConfigParserSupplierTest.java
@@ -0,0 +1,33 @@
+/**
+ * Copyright 2026, Optimizely Inc. and contributors
+ *
+ * Licensed 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 com.optimizely.ab.config.parser;
+
+import com.optimizely.ab.internal.JsonLibraryDetector;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class ConfigParserSupplierTest {
+
+ @Test
+ public void everyConfigParserSupplierClassNameIsAllowlisted() {
+ // guards against adding a parser to the enum and forgetting the JsonLibraryDetector allowlist
+ for (DefaultConfigParser.ConfigParserSupplier supplier : DefaultConfigParser.ConfigParserSupplier.values()) {
+ assertTrue(supplier + " is missing from the JsonLibraryDetector allowlist",
+ JsonLibraryDetector.isAllowed(supplier.getClassName()));
+ }
+ }
+}
diff --git a/core-api/src/test/java/com/optimizely/ab/internal/JsonLibraryDetectorTest.java b/core-api/src/test/java/com/optimizely/ab/internal/JsonLibraryDetectorTest.java
new file mode 100644
index 000000000..2a835e59a
--- /dev/null
+++ b/core-api/src/test/java/com/optimizely/ab/internal/JsonLibraryDetectorTest.java
@@ -0,0 +1,56 @@
+/**
+ * Copyright 2026, Optimizely Inc. and contributors
+ *
+ * Licensed 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 com.optimizely.ab.internal;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class JsonLibraryDetectorTest {
+
+ @Test
+ public void allowlistedLibrariesOnTheClasspathAreDetected() {
+ assertTrue(JsonLibraryDetector.isPresent("com.google.gson.Gson"));
+ assertTrue(JsonLibraryDetector.isPresent("com.fasterxml.jackson.databind.ObjectMapper"));
+ assertTrue(JsonLibraryDetector.isPresent("org.json.JSONObject"));
+ assertTrue(JsonLibraryDetector.isPresent("org.json.simple.JSONObject"));
+ }
+
+ @Test
+ public void classNamesOutsideTheAllowlistAreRejectedEvenWhenTheClassExists() {
+ assertFalse(JsonLibraryDetector.isPresent("java.lang.String"));
+ assertFalse(JsonLibraryDetector.isPresent("java.lang.Runtime"));
+ assertFalse(JsonLibraryDetector.isPresent("com.optimizely.ab.internal.JsonLibraryDetector"));
+ }
+
+ @Test
+ public void everyJsonParserProviderClassNameIsAllowlisted() {
+ // guards against adding a parser to the enum and forgetting the allowlist
+ for (JsonParserProvider provider : JsonParserProvider.values()) {
+ assertTrue(provider + " is missing from the JsonLibraryDetector allowlist",
+ JsonLibraryDetector.isAllowed(provider.getClassName()));
+ }
+ }
+
+ @Test
+ public void unknownAndMalformedNamesAreRejected() {
+ assertFalse(JsonLibraryDetector.isPresent(null));
+ assertFalse(JsonLibraryDetector.isPresent(""));
+ assertFalse(JsonLibraryDetector.isPresent("not.a.real.Clazz"));
+ assertFalse(JsonLibraryDetector.isPresent("com.google.gson.Gson "));
+ }
+}
diff --git a/java-quickstart/build.gradle b/java-quickstart/build.gradle
index ef86b3045..ea4f15a2c 100644
--- a/java-quickstart/build.gradle
+++ b/java-quickstart/build.gradle
@@ -5,9 +5,10 @@ dependencies {
implementation project(':core-httpclient-impl')
// implementation group: 'com.google.code.gson', name: 'gson', version: gsonVersion
- implementation 'com.fasterxml.jackson.core:jackson-core:2.17.0'
- implementation 'com.fasterxml.jackson.core:jackson-annotations:2.17.0'
- implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0'
+ // NOTE: jackson-annotations drops the patch version since Jackson 2.20 (2.23, not 2.23.0)
+ implementation 'com.fasterxml.jackson.core:jackson-core:2.23.0'
+ implementation 'com.fasterxml.jackson.core:jackson-annotations:2.23'
+ implementation 'com.fasterxml.jackson.core:jackson-databind:2.23.0'
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: httpClientVersion
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: log4jVersion