Update exception variable names
Consistently use `ex` for caught exception and `cause` for Exception constructor arguments. Issue gh-8945
This commit is contained in:
+1
-1
@@ -85,7 +85,7 @@ public class DefaultSpringSecurityContextSourceTests {
|
||||
try {
|
||||
ctx = this.contextSource.getContext("uid=Bob,ou=people,dc=springframework,dc=org", "bobspassword");
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
}
|
||||
assertThat(ctx).isNotNull();
|
||||
// com.sun.jndi.ldap.LdapPoolManager.showStats(System.out);
|
||||
|
||||
+10
-10
@@ -69,12 +69,12 @@ public class ApacheDSContainerTests {
|
||||
try {
|
||||
server1.destroy();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
catch (Throwable ex) {
|
||||
}
|
||||
try {
|
||||
server2.destroy();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
catch (Throwable ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,12 +95,12 @@ public class ApacheDSContainerTests {
|
||||
try {
|
||||
server1.destroy();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
catch (Throwable ex) {
|
||||
}
|
||||
try {
|
||||
server2.destroy();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
catch (Throwable ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,8 +116,8 @@ public class ApacheDSContainerTests {
|
||||
server.afterPropertiesSet();
|
||||
fail("Expected an IllegalArgumentException to be thrown.");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertThat(e).hasMessage("When LdapOverSsl is enabled, the keyStoreFile property must be set.");
|
||||
catch (IllegalArgumentException ex) {
|
||||
assertThat(ex).hasMessage("When LdapOverSsl is enabled, the keyStoreFile property must be set.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,9 +143,9 @@ public class ApacheDSContainerTests {
|
||||
server.afterPropertiesSet();
|
||||
fail("Expected a RuntimeException to be thrown.");
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertThat(e).hasMessage("Server startup failed");
|
||||
assertThat(e).hasRootCauseInstanceOf(UnrecoverableKeyException.class);
|
||||
catch (RuntimeException ex) {
|
||||
assertThat(ex).hasMessage("Server startup failed");
|
||||
assertThat(ex).hasRootCauseInstanceOf(UnrecoverableKeyException.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ public class ApacheDSContainerTests {
|
||||
try {
|
||||
server.destroy();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
catch (Throwable ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -75,9 +75,9 @@ public class UnboundIdContainerLdifTests {
|
||||
this.appCtx = new AnnotationConfigApplicationContext(MalformedLdifConfig.class);
|
||||
failBecauseExceptionWasNotThrown(IllegalStateException.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(e.getMessage()).contains("Unable to load LDIF classpath:test-server-malformed.txt");
|
||||
catch (Exception ex) {
|
||||
assertThat(ex.getCause()).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(ex.getMessage()).contains("Unable to load LDIF classpath:test-server-malformed.txt");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,9 +87,9 @@ public class UnboundIdContainerLdifTests {
|
||||
this.appCtx = new AnnotationConfigApplicationContext(MissingLdifConfig.class);
|
||||
failBecauseExceptionWasNotThrown(IllegalStateException.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(e.getMessage()).contains("Unable to load LDIF classpath:does-not-exist.ldif");
|
||||
catch (Exception ex) {
|
||||
assertThat(ex.getCause()).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(ex.getMessage()).contains("Unable to load LDIF classpath:does-not-exist.ldif");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ public final class LdapUtils {
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
catch (NamingException e) {
|
||||
logger.error("Failed to close context.", e);
|
||||
catch (NamingException ex) {
|
||||
logger.error("Failed to close context.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,8 +64,8 @@ public final class LdapUtils {
|
||||
ne.close();
|
||||
}
|
||||
}
|
||||
catch (NamingException e) {
|
||||
logger.error("Failed to close enumeration.", e);
|
||||
catch (NamingException ex) {
|
||||
logger.error("Failed to close enumeration.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,9 +177,9 @@ public final class LdapUtils {
|
||||
try {
|
||||
return new URI(url);
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
catch (URISyntaxException ex) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException("Unable to parse url: " + url);
|
||||
iae.initCause(e);
|
||||
iae.initCause(ex);
|
||||
throw iae;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -197,8 +197,8 @@ public class SpringSecurityLdapTemplate extends LdapTemplate {
|
||||
extractStringAttributeValues(adapter, record, attr.getID());
|
||||
}
|
||||
}
|
||||
catch (NamingException x) {
|
||||
org.springframework.ldap.support.LdapUtils.convertLdapException(x);
|
||||
catch (NamingException ex) {
|
||||
org.springframework.ldap.support.LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -316,7 +316,7 @@ public class SpringSecurityLdapTemplate extends LdapTemplate {
|
||||
results.add(dca);
|
||||
}
|
||||
}
|
||||
catch (PartialResultException e) {
|
||||
catch (PartialResultException ex) {
|
||||
LdapUtils.closeEnumeration(resultsEnum);
|
||||
logger.info("Ignoring PartialResultException");
|
||||
}
|
||||
|
||||
+7
-7
@@ -127,20 +127,20 @@ public class BindAuthenticator extends AbstractLdapAuthenticator {
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (NamingException e) {
|
||||
catch (NamingException ex) {
|
||||
// This will be thrown if an invalid user name is used and the method may
|
||||
// be called multiple times to try different names, so we trap the exception
|
||||
// unless a subclass wishes to implement more specialized behaviour.
|
||||
if ((e instanceof org.springframework.ldap.AuthenticationException)
|
||||
|| (e instanceof org.springframework.ldap.OperationNotSupportedException)) {
|
||||
handleBindException(userDnStr, username, e);
|
||||
if ((ex instanceof org.springframework.ldap.AuthenticationException)
|
||||
|| (ex instanceof org.springframework.ldap.OperationNotSupportedException)) {
|
||||
handleBindException(userDnStr, username, ex);
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
catch (javax.naming.NamingException e) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
catch (javax.naming.NamingException ex) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
finally {
|
||||
LdapUtils.closeContext(ctx);
|
||||
|
||||
+10
-10
@@ -165,12 +165,12 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
ctx = bindAsUser(username, password);
|
||||
return searchForUser(ctx, username);
|
||||
}
|
||||
catch (CommunicationException e) {
|
||||
throw badLdapConnection(e);
|
||||
catch (CommunicationException ex) {
|
||||
throw badLdapConnection(ex);
|
||||
}
|
||||
catch (NamingException e) {
|
||||
this.logger.error("Failed to locate directory entry for authenticated user: " + username, e);
|
||||
throw badCredentials(e);
|
||||
catch (NamingException ex) {
|
||||
this.logger.error("Failed to locate directory entry for authenticated user: " + username, ex);
|
||||
throw badCredentials(ex);
|
||||
}
|
||||
finally {
|
||||
LdapUtils.closeContext(ctx);
|
||||
@@ -222,13 +222,13 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends AbstractLda
|
||||
try {
|
||||
return this.contextFactory.createContext(env);
|
||||
}
|
||||
catch (NamingException e) {
|
||||
if ((e instanceof AuthenticationException) || (e instanceof OperationNotSupportedException)) {
|
||||
handleBindException(bindPrincipal, e);
|
||||
throw badCredentials(e);
|
||||
catch (NamingException ex) {
|
||||
if ((ex instanceof AuthenticationException) || (ex instanceof OperationNotSupportedException)) {
|
||||
handleBindException(bindPrincipal, ex);
|
||||
throw badCredentials(ex);
|
||||
}
|
||||
else {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -38,8 +38,8 @@ public class PasswordPolicyControlExtractor {
|
||||
try {
|
||||
ctrls = ctx.getResponseControls();
|
||||
}
|
||||
catch (javax.naming.NamingException e) {
|
||||
logger.error("Failed to obtain response controls", e);
|
||||
catch (javax.naming.NamingException ex) {
|
||||
logger.error("Failed to obtain response controls", ex);
|
||||
}
|
||||
|
||||
for (int i = 0; ctrls != null && i < ctrls.length; i++) {
|
||||
|
||||
+4
-4
@@ -84,8 +84,8 @@ public class PasswordPolicyResponseControl extends PasswordPolicyControl {
|
||||
try {
|
||||
decoder.decode();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new DataRetrievalFailureException("Failed to parse control value", e);
|
||||
catch (IOException ex) {
|
||||
throw new DataRetrievalFailureException("Failed to parse control value", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,8 +340,8 @@ public class PasswordPolicyResponseControl extends PasswordPolicyControl {
|
||||
// try {
|
||||
// number = ((Long)decoder.decodeNumeric(new ByteArrayInputStream(content),
|
||||
// content.length)).intValue();
|
||||
// } catch(IOException e) {
|
||||
// throw new LdapDataAccessException("Failed to parse number ", e);
|
||||
// } catch(IOException ex) {
|
||||
// throw new LdapDataAccessException("Failed to parse number ", ex);
|
||||
// }
|
||||
//
|
||||
// if(contentTag == 0) {
|
||||
|
||||
+26
-22
@@ -259,29 +259,18 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
this.service.startup();
|
||||
this.server.start();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException("Server startup failed", e);
|
||||
catch (Exception ex) {
|
||||
throw new RuntimeException("Server startup failed", ex);
|
||||
}
|
||||
|
||||
try {
|
||||
this.service.getAdminSession().lookup(this.partition.getSuffixDn());
|
||||
}
|
||||
catch (LdapNameNotFoundException e) {
|
||||
try {
|
||||
LdapDN dn = new LdapDN(this.root);
|
||||
Assert.isTrue(this.root.startsWith("dc="), "root must start with dc=");
|
||||
String dc = this.root.substring(3, this.root.indexOf(','));
|
||||
ServerEntry entry = this.service.newEntry(dn);
|
||||
entry.add("objectClass", "top", "domain", "extensibleObject");
|
||||
entry.add("dc", dc);
|
||||
this.service.getAdminSession().add(entry);
|
||||
}
|
||||
catch (Exception e1) {
|
||||
this.logger.error("Failed to create dc entry", e1);
|
||||
}
|
||||
catch (LdapNameNotFoundException ex) {
|
||||
handleLdapNameNotFoundException();
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.logger.error("Lookup failed", e);
|
||||
catch (Exception ex) {
|
||||
this.logger.error("Lookup failed", ex);
|
||||
}
|
||||
|
||||
SocketAcceptor socketAcceptor = this.server.getSocketAcceptor(this.transport);
|
||||
@@ -293,8 +282,23 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
try {
|
||||
importLdifs();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException("Failed to import LDIF file(s)", e);
|
||||
catch (Exception ex) {
|
||||
throw new RuntimeException("Failed to import LDIF file(s)", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleLdapNameNotFoundException() {
|
||||
try {
|
||||
LdapDN dn = new LdapDN(this.root);
|
||||
Assert.isTrue(this.root.startsWith("dc="), "root must start with dc=");
|
||||
String dc = this.root.substring(3, this.root.indexOf(','));
|
||||
ServerEntry entry = this.service.newEntry(dn);
|
||||
entry.add("objectClass", "top", "domain", "extensibleObject");
|
||||
entry.add("dc", dc);
|
||||
this.service.getAdminSession().add(entry);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
this.logger.error("Failed to create dc entry", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,8 +313,8 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
this.server.stop();
|
||||
this.service.shutdown();
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.logger.error("Shutdown failed", e);
|
||||
catch (Exception ex) {
|
||||
this.logger.error("Shutdown failed", ex);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -350,7 +354,7 @@ public class ApacheDSContainer implements InitializingBean, DisposableBean, Life
|
||||
try {
|
||||
ldifFile = ldifs[0].getFile().getAbsolutePath();
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (IOException ex) {
|
||||
ldifFile = ldifs[0].getURI().toString();
|
||||
}
|
||||
this.logger.info("Loading LDIF file: " + ldifFile);
|
||||
|
||||
+4
-4
@@ -295,7 +295,7 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (org.springframework.ldap.NameNotFoundException e) {
|
||||
catch (org.springframework.ldap.NameNotFoundException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -436,7 +436,7 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
try {
|
||||
ctx.reconnect(null);
|
||||
}
|
||||
catch (javax.naming.AuthenticationException e) {
|
||||
catch (javax.naming.AuthenticationException ex) {
|
||||
throw new BadCredentialsException("Authentication for password change failed.");
|
||||
}
|
||||
|
||||
@@ -459,7 +459,7 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
try {
|
||||
return ctx.extendedOperation(request);
|
||||
}
|
||||
catch (javax.naming.AuthenticationException e) {
|
||||
catch (javax.naming.AuthenticationException ex) {
|
||||
throw new BadCredentialsException("Authentication for password change failed.");
|
||||
}
|
||||
});
|
||||
@@ -563,7 +563,7 @@ public class LdapUserDetailsManager implements UserDetailsManager {
|
||||
try {
|
||||
dest.write(src);
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (IOException ex) {
|
||||
throw new IllegalArgumentException("Failed to BER encode provided value of type: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -365,11 +365,11 @@ public class ActiveDirectoryLdapAuthenticationProviderTests {
|
||||
this.provider.contextFactory = createContextFactoryThrowing(new CommunicationException(msg));
|
||||
this.provider.authenticate(this.joe);
|
||||
}
|
||||
catch (InternalAuthenticationServiceException e) {
|
||||
catch (InternalAuthenticationServiceException ex) {
|
||||
// Since GH-8418 ldap communication exception is wrapped into
|
||||
// InternalAuthenticationServiceException.
|
||||
// This test is about the wrapped exception, so we throw it.
|
||||
throw e.getCause();
|
||||
throw ex.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,11 +419,11 @@ public class ActiveDirectoryLdapAuthenticationProviderTests {
|
||||
}
|
||||
}
|
||||
|
||||
ContextFactory createContextFactoryThrowing(final NamingException e) {
|
||||
ContextFactory createContextFactoryThrowing(final NamingException ex) {
|
||||
return new ContextFactory() {
|
||||
@Override
|
||||
DirContext createContext(Hashtable<?, ?> env) throws NamingException {
|
||||
throw e;
|
||||
throw ex;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user