try to cache xerces security manager (#841)

This commit is contained in:
PJ Fanning 2025-07-11 15:40:14 +01:00 committed by GitHub
parent cb0943970b
commit fa9428511a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -253,8 +253,24 @@ public final class XMLHelper {
return factory;
}
private static Object _xercesSecurityManager;
private static volatile boolean _xercesSecurityManagerSet = false;
private static Object getXercesSecurityManager() {
if (_xercesSecurityManagerSet) {
return _xercesSecurityManager;
} else {
synchronized (XMLHelper.class) {
if (!_xercesSecurityManagerSet) {
_xercesSecurityManager = tryGetXercesSecurityManager();
_xercesSecurityManagerSet = true;
}
}
return _xercesSecurityManager;
}
}
private static Object tryGetXercesSecurityManager() {
// Try built-in JVM one first, standalone if not
for (String securityManagerClassName : SECURITY_MANAGERS) {
try {
@ -272,7 +288,6 @@ public final class XMLHelper {
logThrowable(e, "SAX Feature unsupported", securityManagerClassName);
}
}
return null;
}