8296226: Add constructors (String,Throwable) and (Throwable) to InvalidParameterException

Reviewed-by: mullan, mdoerr
This commit is contained in:
Matthias Baesken 2022-11-07 07:50:12 +00:00
parent 51f8e9b0e1
commit 8836b92593
8 changed files with 60 additions and 13 deletions
src
java.base/share/classes
jdk.crypto.cryptoki/share/classes/sun/security/pkcs11
jdk.crypto.mscapi/windows/classes/sun/security/mscapi
test/jdk
java/security/Exceptions
sun/security/tools/keytool/fakegen/java.base/sun/security/rsa

@ -58,4 +58,44 @@ public class InvalidParameterException extends IllegalArgumentException {
public InvalidParameterException(String msg) {
super(msg);
}
/**
* Constructs an {@code InvalidParameterException} with the specified
* detail message and cause. A detail message is a {@code String}
* that describes this particular exception.
*
* <p>Note that the detail message associated with {@code cause} is
* <i>not</i> automatically incorporated in this exception's detail
* message.
*
* @param msg the detail message (which is saved for later retrieval
* by the {@link Throwable#getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link Throwable#getCause()} method). (A {@code null} value
* is permitted, and indicates that the cause is nonexistent or
* unknown.)
*
* @since 20
*/
public InvalidParameterException(String msg, Throwable cause) {
super(msg, cause);
}
/**
* Constructs an {@code InvalidParameterException} with the specified cause
* and a detail message of {@code (cause==null ? null : cause.toString())}
* (which typically contains the class and detail message of {@code cause}).
* This constructor is useful for exceptions that are little more than
* wrappers for other throwables.
*
* @param cause the cause (which is saved for later retrieval by the
* {@link Throwable#getCause()} method). (A {@code null} value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
*
* @since 20
*/
public InvalidParameterException(Throwable cause) {
super(cause);
}
}

@ -87,7 +87,7 @@ abstract class RSAKeyPairGenerator extends KeyPairGeneratorSpi {
initialize(new RSAKeyGenParameterSpec(keySize,
RSAKeyGenParameterSpec.F4), random);
} catch (InvalidAlgorithmParameterException iape) {
throw new InvalidParameterException(iape.getMessage());
throw new InvalidParameterException(iape);
}
}

@ -335,8 +335,7 @@ final class P11KeyGenerator extends KeyGeneratorSpi {
try {
newSignificantKeySize = checkKeySize(mechanism, keySize, range);
} catch (InvalidAlgorithmParameterException iape) {
throw (InvalidParameterException)
(new InvalidParameterException().initCause(iape));
throw new InvalidParameterException(iape);
}
if ((mechanism == CKM_DES2_KEY_GEN) ||
(mechanism == CKM_DES3_KEY_GEN)) {

@ -151,7 +151,7 @@ final class P11KeyPairGenerator extends KeyPairGeneratorSpi {
try {
checkKeySize(keySize, null);
} catch (InvalidAlgorithmParameterException e) {
throw (InvalidParameterException) new InvalidParameterException(e.getMessage()).initCause(e);
throw new InvalidParameterException(e);
}
this.params = null;
if (algorithm.equals("EC")) {

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, 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
@ -126,9 +126,7 @@ public final class SunPKCS11 extends AuthProvider {
}
});
} catch (PrivilegedActionException pae) {
InvalidParameterException ipe =
new InvalidParameterException("Error configuring SunPKCS11 provider");
throw (InvalidParameterException) ipe.initCause(pae.getException());
throw new InvalidParameterException("Error configuring SunPKCS11 provider", pae.getException());
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2022, 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
@ -72,7 +72,7 @@ public abstract class CKeyPairGenerator extends KeyPairGeneratorSpi {
RSAKeyFactory.checkKeyLengths(keySize, null,
KEY_SIZE_MIN, KEY_SIZE_MAX);
} catch (InvalidKeyException e) {
throw new InvalidParameterException(e.getMessage());
throw new InvalidParameterException(e);
}
this.keySize = keySize;

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, 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
@ -185,6 +185,16 @@ public class ChainingConstructors {
throw new SecurityException("Test 16 failed");
}
InvalidParameterException ipe =
new InvalidParameterException(cause);
if (!ipe.getCause().equals(cause)) {
throw new SecurityException("Test 17 failed");
}
ipe = new InvalidParameterException(MSG, cause);
if (!ipe.getMessage().equals(MSG) || !ipe.getCause().equals(cause)) {
throw new SecurityException("Test 17 failed");
}
/*
SSLException ssle =
new SSLException(cause);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, 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
@ -57,7 +57,7 @@ public abstract class RSAKeyPairGenerator extends KeyPairGeneratorSpi {
initialize(new RSAKeyGenParameterSpec(keySize,
RSAKeyGenParameterSpec.F4), random);
} catch (InvalidAlgorithmParameterException iape) {
throw new InvalidParameterException(iape.getMessage());
throw new InvalidParameterException(iape);
}
}