1
0
mirror of synced 2026-05-22 21:33:16 +00:00

Update exception variable names

Consistently use `ex` for caught exception and `cause` for Exception
constructor arguments.

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-07-28 23:53:30 -07:00
committed by Rob Winch
parent e9130489a6
commit 8d80166aaf
194 changed files with 635 additions and 633 deletions
@@ -107,8 +107,8 @@ public class Argon2PasswordEncoder implements PasswordEncoder {
try {
decoded = Argon2EncodingUtils.decode(encodedPassword);
}
catch (IllegalArgumentException e) {
this.logger.warn("Malformed password hash", e);
catch (IllegalArgumentException ex) {
this.logger.warn("Malformed password hash", ex);
return false;
}
@@ -248,7 +248,7 @@ public final class Base64 {
try {
decode(bytes);
}
catch (InvalidBase64CharacterException e) {
catch (InvalidBase64CharacterException ex) {
return false;
}
return true;
@@ -43,8 +43,8 @@ public final class Utf8 {
return bytesCopy;
}
catch (CharacterCodingException e) {
throw new IllegalArgumentException("Encoding failed", e);
catch (CharacterCodingException ex) {
throw new IllegalArgumentException("Encoding failed", ex);
}
}
@@ -55,8 +55,8 @@ public final class Utf8 {
try {
return CHARSET.newDecoder().decode(ByteBuffer.wrap(bytes)).toString();
}
catch (CharacterCodingException e) {
throw new IllegalArgumentException("Decoding failed", e);
catch (CharacterCodingException ex) {
throw new IllegalArgumentException("Decoding failed", ex);
}
}
@@ -74,8 +74,8 @@ public class BouncyCastleAesCbcBytesEncryptor extends BouncyCastleAesBytesEncryp
try {
bytesWritten += blockCipher.doFinal(buf, bytesWritten);
}
catch (InvalidCipherTextException e) {
throw new IllegalStateException("unable to encrypt/decrypt", e);
catch (InvalidCipherTextException ex) {
throw new IllegalStateException("unable to encrypt/decrypt", ex);
}
if (bytesWritten == buf.length) {
return buf;
@@ -71,8 +71,8 @@ public class BouncyCastleAesGcmBytesEncryptor extends BouncyCastleAesBytesEncryp
try {
bytesWritten += blockCipher.doFinal(buf, bytesWritten);
}
catch (InvalidCipherTextException e) {
throw new IllegalStateException("unable to encrypt/decrypt", e);
catch (InvalidCipherTextException ex) {
throw new IllegalStateException("unable to encrypt/decrypt", ex);
}
if (bytesWritten == buf.length) {
return buf;
@@ -56,11 +56,11 @@ final class CipherUtils {
SecretKeyFactory factory = SecretKeyFactory.getInstance(algorithm);
return factory.generateSecret(keySpec);
}
catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException("Not a valid encryption algorithm", e);
catch (NoSuchAlgorithmException ex) {
throw new IllegalArgumentException("Not a valid encryption algorithm", ex);
}
catch (InvalidKeySpecException e) {
throw new IllegalArgumentException("Not a valid secret key", e);
catch (InvalidKeySpecException ex) {
throw new IllegalArgumentException("Not a valid secret key", ex);
}
}
@@ -71,11 +71,11 @@ final class CipherUtils {
try {
return Cipher.getInstance(algorithm);
}
catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException("Not a valid encryption algorithm", e);
catch (NoSuchAlgorithmException ex) {
throw new IllegalArgumentException("Not a valid encryption algorithm", ex);
}
catch (NoSuchPaddingException e) {
throw new IllegalStateException("Should not happen", e);
catch (NoSuchPaddingException ex) {
throw new IllegalStateException("Should not happen", ex);
}
}
@@ -86,8 +86,8 @@ final class CipherUtils {
try {
return cipher.getParameters().getParameterSpec(parameterSpecClass);
}
catch (InvalidParameterSpecException e) {
throw new IllegalArgumentException("Unable to access parameter", e);
catch (InvalidParameterSpecException ex) {
throw new IllegalArgumentException("Unable to access parameter", ex);
}
}
@@ -117,11 +117,11 @@ final class CipherUtils {
cipher.init(mode, secretKey);
}
}
catch (InvalidKeyException e) {
throw new IllegalArgumentException("Unable to initialize due to invalid secret key", e);
catch (InvalidKeyException ex) {
throw new IllegalArgumentException("Unable to initialize due to invalid secret key", ex);
}
catch (InvalidAlgorithmParameterException e) {
throw new IllegalStateException("Unable to initialize due to invalid decryption parameter spec", e);
catch (InvalidAlgorithmParameterException ex) {
throw new IllegalStateException("Unable to initialize due to invalid decryption parameter spec", ex);
}
}
@@ -133,11 +133,11 @@ final class CipherUtils {
try {
return cipher.doFinal(input);
}
catch (IllegalBlockSizeException e) {
throw new IllegalStateException("Unable to invoke Cipher due to illegal block size", e);
catch (IllegalBlockSizeException ex) {
throw new IllegalStateException("Unable to invoke Cipher due to illegal block size", ex);
}
catch (BadPaddingException e) {
throw new IllegalStateException("Unable to invoke Cipher due to bad padding", e);
catch (BadPaddingException ex) {
throw new IllegalStateException("Unable to invoke Cipher due to bad padding", ex);
}
}
@@ -64,8 +64,8 @@ final class Digester {
try {
return MessageDigest.getInstance(algorithm);
}
catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("No such hashing algorithm", e);
catch (NoSuchAlgorithmException ex) {
throw new IllegalStateException("No such hashing algorithm", ex);
}
}
@@ -104,7 +104,7 @@ public class LdapShaPasswordEncoder implements PasswordEncoder {
sha = MessageDigest.getInstance("SHA");
sha.update(Utf8.encode(rawPassword));
}
catch (java.security.NoSuchAlgorithmException e) {
catch (java.security.NoSuchAlgorithmException ex) {
throw new IllegalStateException("No SHA implementation available!");
}
@@ -112,8 +112,8 @@ public class Pbkdf2PasswordEncoder implements PasswordEncoder {
try {
SecretKeyFactory.getInstance(algorithmName);
}
catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException("Invalid algorithm '" + algorithmName + "'.", e);
catch (NoSuchAlgorithmException ex) {
throw new IllegalArgumentException("Invalid algorithm '" + algorithmName + "'.", ex);
}
this.algorithm = algorithmName;
}
@@ -163,8 +163,8 @@ public class Pbkdf2PasswordEncoder implements PasswordEncoder {
SecretKeyFactory skf = SecretKeyFactory.getInstance(this.algorithm);
return EncodingUtils.concatenate(salt, skf.generateSecret(spec).getEncoded());
}
catch (GeneralSecurityException e) {
throw new IllegalStateException("Could not create hash", e);
catch (GeneralSecurityException ex) {
throw new IllegalStateException("Could not create hash", ex);
}
}
@@ -41,11 +41,11 @@ public class CryptoAssumptions {
Cipher.getInstance(cipherAlgorithm.toString());
aes256Available = Cipher.getMaxAllowedKeyLength("AES") >= 256;
}
catch (NoSuchAlgorithmException e) {
throw new AssumptionViolatedException(cipherAlgorithm + " not available, skipping test", e);
catch (NoSuchAlgorithmException ex) {
throw new AssumptionViolatedException(cipherAlgorithm + " not available, skipping test", ex);
}
catch (NoSuchPaddingException e) {
throw new AssumptionViolatedException(cipherAlgorithm + " padding not available, skipping test", e);
catch (NoSuchPaddingException ex) {
throw new AssumptionViolatedException(cipherAlgorithm + " padding not available, skipping test", ex);
}
Assume.assumeTrue("AES key length of 256 not allowed, skipping test", aes256Available);