diff options
| author | Raif S. Naffah <raif@swiftdsl.com.au> | 2006-08-13 00:09:58 +0000 |
|---|---|---|
| committer | Raif S. Naffah <raif@swiftdsl.com.au> | 2006-08-13 00:09:58 +0000 |
| commit | 04f3e82ec5a636855d68f80630d61355cf0560fb (patch) | |
| tree | 680f41705bc16d10c63b8aea4c993e826cd14613 /java/security/cert/CertPathBuilder.java | |
| parent | ff16c332b4e181ea6b1e1175f3b504fb4e8e992b (diff) | |
| download | classpath-04f3e82ec5a636855d68f80630d61355cf0560fb.tar.gz | |
2006-08-13 Raif S. Naffah <raif@swiftdsl.com.au>
PR Classpath/28678
* gnu/java/security/Engine.java (getInstance(String, String, Provider)):
Updated documentation.
Formatting.
(getInstance(String, String, Provider, Object[])): Likewise.
Separate checks for null and empty string arguments.
Include as much information as possible in the exception's message.
Do not swallow original exception; instead use it as the cause of the
resulting exception.
* gnu/javax/security/auth/callback/AbstractCallbackHandler.java
(getInstance(String)): Updated documentation.
Formatting.
Store last exception caught when iterating through all providers.
If no implementation found, raise last exception if one was caught.
(getInstance(String, String)): Updated documentation.
Formatting.
Check for null or empty provider as per RI-5's documentation.
(getInstance(String, Provider)): Updated documentation.
Formatting.
Use as much information as possible in the exception message.
Do not swallow original exception; instead use it as the cause for the
ultimate raised exception(s).
* java/security/cert/CertificateFactory.java: Likewise.
* java/security/cert/CertPathBuilder.java: Likewise.
* java/security/cert/CertPathValidator.java: Likewise.
* java/security/cert/CertStore.java: Likewise.
* java/security/AlgorithmParameterGenerator.java: Likewise.
* java/security/AlgorithmParameters.java: Likewise.
* java/security/KeyFactory.java: Likewise.
* java/security/KeyPairGenerator.java: Likewise.
* java/security/KeyStore.java: Likewise.
* java/security/MessageDigest.java: Likewise.
* java/security/SecureRandom.java: Likewise.
* java/security/Signature.java: Likewise.
* javax/crypto/Cipher.java: Likewise.
* javax/crypto/ExemptionMechanism.java: Likewise.
* javax/crypto/KeyAgreement.java: Likewise.
* javax/crypto/KeyGenerator.java: Likewise.
* javax/crypto/Mac.java: Likewise.
* javax/crypto/SecretKeyFactory.java: Likewise.
* javax/net/ssl/KeyManagerFactory.java: Likewise.
* javax/net/ssl/SSLContext.java: Likewise.
* javax/net/ssl/TrustManagerFactory.java: Likewise.
Diffstat (limited to 'java/security/cert/CertPathBuilder.java')
| -rw-r--r-- | java/security/cert/CertPathBuilder.java | 113 |
1 files changed, 62 insertions, 51 deletions
diff --git a/java/security/cert/CertPathBuilder.java b/java/security/cert/CertPathBuilder.java index f6965205f..519ed2b6c 100644 --- a/java/security/cert/CertPathBuilder.java +++ b/java/security/cert/CertPathBuilder.java @@ -40,6 +40,7 @@ package java.security.cert; import gnu.java.security.Engine; +import java.lang.reflect.InvocationTargetException; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; @@ -111,50 +112,54 @@ public class CertPathBuilder } /** - * Get an instance of a named CertPathBuilder, from the first provider - * that implements it. - * - * @param algorithm The name of the CertPathBuilder to create. + * Returns an instance of a named <code>CertPathBuilder</code> from the + * first provider that implements it. + * + * @param algorithm The name of the <code>CertPathBuilder</code> to create. * @return The new instance. - * @throws NoSuchAlgorithmException If no installed provider - * implements the named algorithm. + * @throws NoSuchAlgorithmException If no installed provider implements the + * named algorithm. + * @throws IllegalArgumentException if <code>algorithm</code> is + * <code>null</code> or is an empty string. */ public static CertPathBuilder getInstance(String algorithm) - throws NoSuchAlgorithmException + throws NoSuchAlgorithmException { Provider[] p = Security.getProviders(); - + NoSuchAlgorithmException lastException = null; for (int i = 0; i < p.length; i++) - { - try - { - return getInstance(algorithm, p[i]); - } - catch (NoSuchAlgorithmException e) - { - // Ignored. - } - } - + try + { + return getInstance(algorithm, p[i]); + } + catch (NoSuchAlgorithmException x) + { + lastException = x; + } + if (lastException != null) + throw lastException; throw new NoSuchAlgorithmException(algorithm); } /** - * Get an instance of a named CertPathBuilder from the named + * Returns an instance of a named <code>CertPathBuilder</code> from a named * provider. - * - * @param algorithm The name of the CertPathBuilder to create. - * @param provider The name of the provider from which to get the - * implementation. + * + * @param algorithm The name of the <code>CertPathBuilder</code> to create. + * @param provider The name of the provider to use. * @return The new instance. - * @throws NoSuchAlgorithmException If no installed provider - * implements the named algorithm. - * @throws NoSuchProviderException If the named provider does not - * exist. + * @throws NoSuchAlgorithmException If no installed provider implements the + * named algorithm. + * @throws NoSuchProviderException If the named provider does not exist. + * @throws IllegalArgumentException if either <code>algorithm</code> or + * <code>provider</code> is <code>null</code>, or if + * <code>algorithm</code> is an empty string. */ public static CertPathBuilder getInstance(String algorithm, String provider) - throws NoSuchAlgorithmException, NoSuchProviderException + throws NoSuchAlgorithmException, NoSuchProviderException { + if (provider == null) + throw new IllegalArgumentException("provider MUST NOT be null"); Provider p = Security.getProvider(provider); if (p == null) throw new NoSuchProviderException(provider); @@ -162,41 +167,47 @@ public class CertPathBuilder } /** - * Get an instance of a named CertPathBuilder from the specified - * provider. - * - * @param algorithm The name of the CertPathBuilder to create. - * @param provider The provider from which to get the implementation. + * Returns an instance of a named <code>CertPathBuilder</code> from the + * specified provider. + * + * @param algorithm The name of the <code>CertPathBuilder</code> to create. + * @param provider The provider to use. * @return The new instance. - * @throws NoSuchAlgorithmException If no installed provider - * implements the named algorithm. - * @throws IllegalArgumentException If <i>provider</i> in - * <tt>null</tt>. + * @throws NoSuchAlgorithmException If no installed provider implements the + * named algorithm. + * @throws IllegalArgumentException if either <code>algorithm</code> or + * <code>provider</code> is <code>null</code>, or if + * <code>algorithm</code> is an empty string. */ public static CertPathBuilder getInstance(String algorithm, Provider provider) - throws NoSuchAlgorithmException + throws NoSuchAlgorithmException { - if (provider == null) - throw new IllegalArgumentException("null provider"); + StringBuilder sb = new StringBuilder("CertPathBuilder for algorithm [") + .append(algorithm).append("] from provider[") + .append(provider).append("] could not be created"); + Throwable cause; try { - return new CertPathBuilder((CertPathBuilderSpi) - Engine.getInstance(CERT_PATH_BUILDER, algorithm, provider), - provider, algorithm); + Object spi = Engine.getInstance(CERT_PATH_BUILDER, algorithm, provider); + return new CertPathBuilder((CertPathBuilderSpi) spi, provider, algorithm); } - catch (java.lang.reflect.InvocationTargetException ite) + catch (InvocationTargetException x) { - throw new NoSuchAlgorithmException(algorithm); + cause = x.getCause(); + if (cause instanceof NoSuchAlgorithmException) + throw (NoSuchAlgorithmException) cause; + if (cause == null) + cause = x; } - catch (ClassCastException cce) + catch (ClassCastException x) { - throw new NoSuchAlgorithmException(algorithm); + cause = x; } + NoSuchAlgorithmException x = new NoSuchAlgorithmException(sb.toString()); + x.initCause(cause); + throw x; } - // Instance methods. - // ------------------------------------------------------------------------ - /** * Return the name of this CertPathBuilder algorithm. * |
