Skip to content

Commit

Permalink
Adopt "JDK-8324646: Avoid Class.forName in SecureRandom constructor"
Browse files Browse the repository at this point in the history
Fixes #716

(cherry picked from commit 39988d3)
  • Loading branch information
zakkak committed May 28, 2024
1 parent 472c437 commit 0ca9d87
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,15 @@ private static boolean isValid(Service s) {
private static Function<String, Class<?>> getConstructorParameterClassAccessor(ImageClassLoader loader) {
Map<String, /* EngineDescription */ Object> 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
Expand All @@ -678,10 +686,10 @@ private static Function<String, Class<?>> 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);
}
Expand Down

0 comments on commit 0ca9d87

Please sign in to comment.