Skip to content

Commit

Permalink
8296226: Add constructors (String,Throwable) and (Throwable) to Inval…
Browse files Browse the repository at this point in the history
…idParameterException

Reviewed-by: mullan, mdoerr
  • Loading branch information
MBaesken committed Nov 7, 2022
1 parent 51f8e9b commit 8836b92
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 13 deletions.
Expand Up @@ -58,4 +58,44 @@ public InvalidParameterException() {
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);
}
}
Expand Up @@ -87,7 +87,7 @@ public void initialize(int keySize, SecureRandom random) {
initialize(new RSAKeyGenParameterSpec(keySize,
RSAKeyGenParameterSpec.F4), random);
} catch (InvalidAlgorithmParameterException iape) {
throw new InvalidParameterException(iape.getMessage());
throw new InvalidParameterException(iape);
}
}

Expand Down
Expand Up @@ -335,8 +335,7 @@ protected void engineInit(int keySize, SecureRandom random) {
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)) {
Expand Down
Expand Up @@ -151,7 +151,7 @@ public void initialize(int keySize, SecureRandom random) {
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")) {
Expand Down
@@ -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
Expand Down Expand Up @@ -126,9 +126,7 @@ public SunPKCS11 run() throws Exception {
}
});
} 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());
}
}

Expand Down
@@ -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
Expand Down Expand Up @@ -72,7 +72,7 @@ public void initialize(int keySize, SecureRandom random) {
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;
Expand Down
12 changes: 11 additions & 1 deletion test/jdk/java/security/Exceptions/ChainingConstructors.java
@@ -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
Expand Down Expand Up @@ -185,6 +185,16 @@ public static void main(String[] args) throws Exception {
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);
Expand Down
@@ -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
Expand Down Expand Up @@ -57,7 +57,7 @@ public void initialize(int keySize, SecureRandom random) {
initialize(new RSAKeyGenParameterSpec(keySize,
RSAKeyGenParameterSpec.F4), random);
} catch (InvalidAlgorithmParameterException iape) {
throw new InvalidParameterException(iape.getMessage());
throw new InvalidParameterException(iape);
}
}

Expand Down

1 comment on commit 8836b92

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.