Skip to content

Commit

Permalink
8295405: Add cause in a couple of IllegalArgumentException and Invali…
Browse files Browse the repository at this point in the history
…dParameterException shown by sun/security/pkcs11 tests

Backport-of: d5d34241e21305379f1858556f225e7645cd294e
  • Loading branch information
MBaesken committed Nov 25, 2022
1 parent 22ad409 commit 44c8733
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 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 @@ -160,7 +160,7 @@ public void generate(String name) {
}

} catch (Exception e) {
throw new IllegalArgumentException(e.getMessage());
throw new IllegalArgumentException(e.getMessage(), e);
}
generateInternal();
}
Expand All @@ -176,7 +176,7 @@ public void generate(int keyBits) {
keyGen.initialize(keyBits, prng);

} catch (Exception e) {
throw new IllegalArgumentException(e.getMessage());
throw new IllegalArgumentException(e.getMessage(), e);
}
}
generateInternal();
Expand Down Expand Up @@ -349,7 +349,7 @@ public X509Certificate getSelfCertificate (X500Name myname, Date firstDate,

} catch (IOException e) {
throw new CertificateEncodingException("getSelfCert: " +
e.getMessage());
e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ private static String expand(final String s) throws IOException {
try {
return PropertyExpander.expand(s);
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
throw new RuntimeException(e.getMessage(), e);
}
}

Expand Down Expand Up @@ -396,6 +396,10 @@ private ConfigurationException excLine(String msg) {
return new ConfigurationException(msg + ", line " + st.lineno());
}

private ConfigurationException excLine(String msg, Throwable e) {
return new ConfigurationException(msg + ", line " + st.lineno(), e);
}

private void parse() throws IOException {
while (true) {
int token = nextToken();
Expand Down Expand Up @@ -792,7 +796,7 @@ private long parseMechanism(String mech) throws IOException {
try {
return Functions.getMechanismId(mech);
} catch (IllegalArgumentException e) {
throw excLine("Unknown mechanism: " + mech);
throw excLine("Unknown mechanism: " + mech, e);
}
}
}
Expand Down Expand Up @@ -952,7 +956,7 @@ private long parseObjectClass() throws IOException {
try {
return Functions.getObjectClassId(name);
} catch (IllegalArgumentException e) {
throw excLine("Unknown object class " + name);
throw excLine("Unknown object class " + name, e);
}
}

Expand All @@ -964,7 +968,7 @@ private long parseKeyAlgorithm() throws IOException {
try {
return Functions.getKeyId(name);
} catch (IllegalArgumentException e) {
throw excLine("Unknown key algorithm " + name);
throw excLine("Unknown key algorithm " + name, e);
}
}
}
Expand All @@ -976,7 +980,7 @@ private long decodeAttributeName(String name) throws IOException {
try {
return Functions.getAttributeId(name);
} catch (IllegalArgumentException e) {
throw excLine("Unknown attribute name " + name);
throw excLine("Unknown attribute name " + name, e);
}
}
}
Expand Down Expand Up @@ -1032,4 +1036,8 @@ class ConfigurationException extends IOException {
ConfigurationException(String msg) {
super(msg);
}

ConfigurationException(String msg, Throwable e) {
super(msg, e);
}
}
Original file line number Diff line number Diff line change
@@ -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 @@ -140,7 +140,7 @@ private enum Transformation {
try {
engineSetPadding(algoParts[2]);
} catch (NoSuchPaddingException e) {
throw new NoSuchAlgorithmException();
throw new NoSuchAlgorithmException(e);
}
} else if (algoParts[0].equals("ChaCha20-Poly1305")) {
fixedKeySize = 32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void initialize(int keySize, SecureRandom random) {
try {
checkKeySize(keySize, null);
} catch (InvalidAlgorithmParameterException e) {
throw new InvalidParameterException(e.getMessage());
throw (InvalidParameterException) new InvalidParameterException(e.getMessage()).initCause(e);
}
this.params = null;
if (algorithm.equals("EC")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ private PrivateKey loadPkey(Session session, long oHandle)
RSAKeyFactory.checkKeyLengths(keyLength, null,
-1, Integer.MAX_VALUE);
} catch (InvalidKeyException e) {
throw new KeyStoreException(e.getMessage());
throw new KeyStoreException(e.getMessage(), e);
}

return P11Key.privateKey(session,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ private void checkRSAKeyLength(int len) throws InvalidKeyException {
padding = RSAPadding.getInstance
(RSAPadding.PAD_BLOCKTYPE_1, (len + 7) >> 3);
} catch (InvalidAlgorithmParameterException iape) {
throw new InvalidKeyException(iape.getMessage());
throw new InvalidKeyException(iape.getMessage(), iape);
}
int maxDataSize = padding.getMaxDataSize();
int encodedLength = switch (algorithm) {
Expand Down Expand Up @@ -804,7 +804,7 @@ private static byte[] dsaToASN1(byte[] signature) {
DerValue result = new DerValue(DerValue.tag_Sequence,
outseq.toByteArray());
return result.toByteArray();
} catch (java.io.IOException e) {
} catch (IOException e) {
throw new RuntimeException("Internal error", e);
}
}
Expand Down

1 comment on commit 44c8733

@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.