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

View File

@@ -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;
}
}

View File

@@ -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");
}

View File

@@ -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);

View File

@@ -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);
}
}
}

View File

@@ -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++) {

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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);
}
}