8035004: Provider provides less service
Reviewed-by: wetmore, skoivu
This commit is contained in:
parent
33df051faf
commit
9d3f23b245
@ -1376,7 +1376,7 @@ public abstract class Provider extends Properties {
|
||||
* <p>This class defines the methods {@link #supportsParameter
|
||||
* supportsParameter()} and {@link #newInstance newInstance()}
|
||||
* which are used by the Java security framework when it searches for
|
||||
* suitable services and instantes them. The valid arguments to those
|
||||
* suitable services and instantiates them. The valid arguments to those
|
||||
* methods depend on the type of service. For the service types defined
|
||||
* within Java SE, see the
|
||||
* <a href="../../../technotes/guides/security/crypto/CryptoSpec.html">
|
||||
@ -1566,7 +1566,7 @@ public abstract class Provider extends Properties {
|
||||
*
|
||||
* @throws InvalidParameterException if the value of
|
||||
* constructorParameter is invalid for this type of service.
|
||||
* @throws NoSuchAlgorithmException if instantation failed for
|
||||
* @throws NoSuchAlgorithmException if instantiation failed for
|
||||
* any other reason.
|
||||
*/
|
||||
public Object newInstance(Object constructorParameter)
|
||||
@ -1594,7 +1594,9 @@ public abstract class Provider extends Properties {
|
||||
+ " engines");
|
||||
}
|
||||
Class<?> clazz = getImplClass();
|
||||
return clazz.newInstance();
|
||||
Class<?>[] empty = {};
|
||||
Constructor<?> con = clazz.getConstructor(empty);
|
||||
return con.newInstance();
|
||||
} else {
|
||||
Class<?> paramClass = cap.getConstructorParameterClass();
|
||||
if (constructorParameter != null) {
|
||||
@ -1637,13 +1639,18 @@ public abstract class Provider extends Properties {
|
||||
} else {
|
||||
clazz = cl.loadClass(className);
|
||||
}
|
||||
if (!Modifier.isPublic(clazz.getModifiers())) {
|
||||
throw new NoSuchAlgorithmException
|
||||
("class configured for " + type + " (provider: " +
|
||||
provider.getName() + ") is not public.");
|
||||
}
|
||||
classRef = new WeakReference<Class<?>>(clazz);
|
||||
}
|
||||
return clazz;
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new NoSuchAlgorithmException
|
||||
("class configured for " + type + "(provider: " +
|
||||
provider.getName() + ")" + "cannot be found.", e);
|
||||
("class configured for " + type + " (provider: " +
|
||||
provider.getName() + ") cannot be found.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1656,15 +1663,21 @@ public abstract class Provider extends Properties {
|
||||
throws Exception {
|
||||
Class<?> clazz = getImplClass();
|
||||
if (constructorParameter == null) {
|
||||
Object o = clazz.newInstance();
|
||||
return o;
|
||||
// create instance with public no-arg constructor if it exists
|
||||
try {
|
||||
Class<?>[] empty = {};
|
||||
Constructor<?> con = clazz.getConstructor(empty);
|
||||
return con.newInstance();
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new NoSuchAlgorithmException("No public no-arg "
|
||||
+ "constructor found in class " + className);
|
||||
}
|
||||
}
|
||||
Class<?> argClass = constructorParameter.getClass();
|
||||
Constructor<?>[] cons = clazz.getConstructors();
|
||||
// find first public constructor that can take the
|
||||
// argument as parameter
|
||||
for (int i = 0; i < cons.length; i++) {
|
||||
Constructor<?> con = cons[i];
|
||||
for (Constructor<?> con : cons) {
|
||||
Class<?>[] paramTypes = con.getParameterTypes();
|
||||
if (paramTypes.length != 1) {
|
||||
continue;
|
||||
@ -1672,10 +1685,9 @@ public abstract class Provider extends Properties {
|
||||
if (paramTypes[0].isAssignableFrom(argClass) == false) {
|
||||
continue;
|
||||
}
|
||||
Object o = con.newInstance(new Object[] {constructorParameter});
|
||||
return o;
|
||||
return con.newInstance(constructorParameter);
|
||||
}
|
||||
throw new NoSuchAlgorithmException("No constructor matching "
|
||||
throw new NoSuchAlgorithmException("No public constructor matching "
|
||||
+ argClass.getName() + " found in class " + className);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user