--- old/src/java.base/share/classes/java/security/Provider.java Mon Jun 8 21:35:03 2015 +++ new/src/java.base/share/classes/java/security/Provider.java Mon Jun 8 21:35:03 2015 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -49,7 +49,10 @@ * * *

Each provider has a name and a version number, and is configured - * in each runtime it is installed in. + * in each runtime it is installed in. A provider normally identifies itself + * with a file named java.security.Provider in the resource directory + * META-INF/services. The file should contain a list of fully-qualified provider + * class names, one per line. * *

See The Provider Class @@ -121,6 +124,18 @@ private transient boolean initialized; + private static Object newInstanceUtil(final Class clazz, + final Class ctrParamClz, final Object ctorParamObj) + throws Exception { + if (ctrParamClz == null) { + Constructor con = clazz.getConstructor(); + return con.newInstance(); + } else { + Constructor con = clazz.getConstructor(ctrParamClz); + return con.newInstance(ctorParamObj); + } + } + /** * Constructs a provider with the specified name, version number, * and information. @@ -140,6 +155,34 @@ } /** + * Apply the supplied configuration argument to this provider instance + * and return the configured provider. Note that if this provider cannot + * be configured in-place, a new provider will be created and returned. + * Therefore, callers should always use the returned provider. + * + * @implSpec + * The default implementation throws {@code UnsupportedOperationException}. + * Subclasses should override this method only if a configuration argument + * is supported. + * + * @param configArg the configuration information for configuring this + * provider. + * + * @throws UnsupportedOperationException if a configuration argument is + * not supported. + * @throws NullPointerException if the supplied configuration argument is + null. + * @throws InvalidParameterException if the supplied configuration argument + * is invalid. + * @return a provider configured with the supplied configuration argument. + * + * @since 1.9 + */ + public Provider configure(String configArg) { + throw new UnsupportedOperationException("configure is not supported"); + } + + /** * Returns the name of this provider. * * @return the name of this provider. @@ -212,8 +255,8 @@ /** * Reads a property list (key and element pairs) from the input stream. * - * @param inStream the input stream. - * @exception IOException if an error occurred when reading from the + * @param inStream the input stream. + * @exception IOException if an error occurred when reading from the * input stream. * @see java.util.Properties#load */ @@ -1579,6 +1622,7 @@ } registered = true; } + Class ctrParamClz; try { EngineDescription cap = knownEngines.get(type); if (cap == null) { @@ -1585,33 +1629,28 @@ // unknown engine type, use generic code // this is the code path future for non-core // optional packages - return newInstanceGeneric(constructorParameter); - } - if (cap.constructorParameterClassName == null) { - if (constructorParameter != null) { - throw new InvalidParameterException - ("constructorParameter not used with " + type - + " engines"); - } - Class clazz = getImplClass(); - Class[] empty = {}; - Constructor con = clazz.getConstructor(empty); - return con.newInstance(); + ctrParamClz = constructorParameter == null? + null : constructorParameter.getClass(); } else { - Class paramClass = cap.getConstructorParameterClass(); + ctrParamClz = cap.constructorParameterClassName == null? + null : Class.forName(cap.constructorParameterClassName); if (constructorParameter != null) { - Class argClass = constructorParameter.getClass(); - if (paramClass.isAssignableFrom(argClass) == false) { + if (ctrParamClz == null) { throw new InvalidParameterException - ("constructorParameter must be instanceof " - + cap.constructorParameterClassName.replace('$', '.') - + " for engine type " + type); + ("constructorParameter not used with " + type + + " engines"); + } else { + Class argClass = constructorParameter.getClass(); + if (ctrParamClz.isAssignableFrom(argClass) == false) { + throw new InvalidParameterException + ("constructorParameter must be instanceof " + + cap.constructorParameterClassName.replace('$', '.') + + " for engine type " + type); + } } } - Class clazz = getImplClass(); - Constructor cons = clazz.getConstructor(paramClass); - return cons.newInstance(constructorParameter); } + return newInstanceUtil(getImplClass(), ctrParamClz, constructorParameter); } catch (NoSuchAlgorithmException e) { throw e; } catch (InvocationTargetException e) { @@ -1654,43 +1693,6 @@ } } - /** - * Generic code path for unknown engine types. Call the - * no-args constructor if constructorParameter is null, otherwise - * use the first matching constructor. - */ - private Object newInstanceGeneric(Object constructorParameter) - throws Exception { - Class clazz = getImplClass(); - if (constructorParameter == null) { - // 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 (Constructor con : cons) { - Class[] paramTypes = con.getParameterTypes(); - if (paramTypes.length != 1) { - continue; - } - if (paramTypes[0].isAssignableFrom(argClass) == false) { - continue; - } - return con.newInstance(constructorParameter); - } - throw new NoSuchAlgorithmException("No public constructor matching " - + argClass.getName() + " found in class " + className); - } - /** * Test whether this Service can use the specified parameter. * Returns false if this service cannot use the parameter. Returns