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
  • Loading branch information
zakkak committed Apr 27, 2024
1 parent 4cc6ec2 commit c35c2d5
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,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 @@ -684,10 +692,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 c35c2d5

Please sign in to comment.