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
Version agnostic adaptation of 05c1e79
(cherry picked from commit 0edb942)

Fix missing null check in 'Adopt "JDK-8324646: Avoid Class.forName in SecureRandom constructor"'

(cherry picked from commit dcecff7)

Fixes #779
  • Loading branch information
zakkak committed Aug 21, 2024
1 parent d4f3b7e commit 9504af6
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,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 @@ -700,9 +708,12 @@ 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("constructorParameterClass")) {
return (Class<?>) consParamClassFieldFinal.get(engineDescription);
}
String constructorParameterClassName = (String) consParamClassFieldFinal.get(engineDescription);
if (constructorParameterClassName != null) {
return loader.findClass(constructorParameterClassName).get();
}
} catch (IllegalAccessException e) {
VMError.shouldNotReachHere(e);
Expand Down

0 comments on commit 9504af6

Please sign in to comment.