From 0edb942475a39226d5c68495433e3ea5049b2459 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Wed, 24 Apr 2024 15:13:07 +0300 Subject: [PATCH] Adopt "JDK-8324646: Avoid Class.forName in SecureRandom constructor" Fixes https://github.com/graalvm/mandrel/issues/716 (cherry picked from commit 39988d343d32ec99d86dbd57f2c55200233c9815) --- .../svm/hosted/SecurityServicesFeature.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java index 0a7b66da9b40..79e39b3a0e68 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java @@ -653,7 +653,15 @@ private static boolean isValid(Service s) { private static Function> getConstructorParameterClassAccessor(ImageClassLoader loader) { Map knownEngines = ReflectionUtil.readStaticField(Provider.class, "knownEngines"); Class clazz = loader.findClassOrFail("java.security.Provider$EngineDescription"); - Field consParamClassNameField = ReflectionUtil.lookupField(clazz, "constructorParameterClassName"); + Field consParamClassField; + + try { + consParamClassField = ReflectionUtil.lookupField(clazz, "constructorParameterClassName"); + } catch (ReflectionUtil.ReflectionUtilError e) { + consParamClassField = ReflectionUtil.lookupField(clazz, "constructorParameterClass"); + } + + final Field consParamClassFieldFinal = consParamClassField; /* * The returned lambda captures the value of the Provider.knownEngines map retrieved above @@ -678,10 +686,10 @@ private static Function> getConstructorParameterClassAccessor(I if (engineDescription == null) { return null; } - String constrParamClassName = (String) consParamClassNameField.get(engineDescription); - if (constrParamClassName != null) { - return loader.findClass(constrParamClassName).get(); + if (consParamClassFieldFinal.getName().equals("constructorParameterClassName")) { + return loader.findClass((String) consParamClassFieldFinal.get(engineDescription)).get(); } + return (Class) consParamClassFieldFinal.get(engineDescription); } catch (IllegalAccessException e) { VMError.shouldNotReachHere(e); }