1
0
mirror of synced 2026-08-05 01:36:56 +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
@@ -178,8 +178,8 @@ public class FilterChainProxy extends GenericFilterBean {
request.setAttribute(FILTER_APPLIED, Boolean.TRUE);
doFilterInternal(request, response, chain);
}
catch (RequestRejectedException e) {
this.requestRejectedHandler.handle((HttpServletRequest) request, (HttpServletResponse) response, e);
catch (RequestRejectedException ex) {
this.requestRejectedHandler.handle((HttpServletRequest) request, (HttpServletResponse) response, ex);
}
finally {
SecurityContextHolder.clearContext();
@@ -72,7 +72,7 @@ public final class ExpressionBasedFilterInvocationSecurityMetadataSource
try {
attributes.add(new WebExpressionConfigAttribute(parser.parseExpression(expression), postProcessor));
}
catch (ParseException e) {
catch (ParseException ex) {
throw new IllegalArgumentException("Failed to parse expression '" + expression + "'");
}
@@ -156,8 +156,8 @@ public class AuthenticationFilter extends OncePerRequestFilter {
successfulAuthentication(request, response, filterChain, authenticationResult);
}
catch (AuthenticationException e) {
unsuccessfulAuthentication(request, response, e);
catch (AuthenticationException ex) {
unsuccessfulAuthentication(request, response, ex);
}
}
@@ -109,9 +109,9 @@ public abstract class AbstractPreAuthenticatedProcessingFilter extends GenericFi
try {
super.afterPropertiesSet();
}
catch (ServletException e) {
catch (ServletException ex) {
// convert to RuntimeException for passivity on afterPropertiesSet signature
throw new RuntimeException(e);
throw new RuntimeException(ex);
}
Assert.notNull(this.authenticationManager, "An AuthenticationManager must be set");
}
@@ -118,15 +118,15 @@ public class WebXmlMappableAttributesRetriever
doc = db.parse(aStream);
return doc;
}
catch (FactoryConfigurationError | IOException | SAXException | ParserConfigurationException e) {
throw new RuntimeException("Unable to parse document object", e);
catch (FactoryConfigurationError | IOException | SAXException | ParserConfigurationException ex) {
throw new RuntimeException("Unable to parse document object", ex);
}
finally {
try {
aStream.close();
}
catch (IOException e) {
this.logger.warn("Failed to close input stream for web.xml", e);
catch (IOException ex) {
this.logger.warn("Failed to close input stream for web.xml", ex);
}
}
}
@@ -137,9 +137,9 @@ final class DefaultWASUsernameAndGroupsExtractor implements WASUsernameAndGroups
return new ArrayList(groups);
}
catch (Exception e) {
logger.error("Exception occured while looking up groups for user", e);
throw new RuntimeException("Exception occured while looking up groups for user", e);
catch (Exception ex) {
logger.error("Exception occured while looking up groups for user", ex);
throw new RuntimeException("Exception occured while looking up groups for user", ex);
}
finally {
try {
@@ -147,8 +147,8 @@ final class DefaultWASUsernameAndGroupsExtractor implements WASUsernameAndGroups
ic.close();
}
}
catch (NamingException e) {
logger.debug("Exception occured while closing context", e);
catch (NamingException ex) {
logger.debug("Exception occured while closing context", ex);
}
}
}
@@ -157,23 +157,23 @@ final class DefaultWASUsernameAndGroupsExtractor implements WASUsernameAndGroups
try {
return method.invoke(instance, args);
}
catch (IllegalArgumentException e) {
catch (IllegalArgumentException ex) {
logger.error("Error while invoking method " + method.getClass().getName() + "." + method.getName() + "("
+ Arrays.asList(args) + ")", e);
+ Arrays.asList(args) + ")", ex);
throw new RuntimeException("Error while invoking method " + method.getClass().getName() + "."
+ method.getName() + "(" + Arrays.asList(args) + ")", e);
+ method.getName() + "(" + Arrays.asList(args) + ")", ex);
}
catch (IllegalAccessException e) {
catch (IllegalAccessException ex) {
logger.error("Error while invoking method " + method.getClass().getName() + "." + method.getName() + "("
+ Arrays.asList(args) + ")", e);
+ Arrays.asList(args) + ")", ex);
throw new RuntimeException("Error while invoking method " + method.getClass().getName() + "."
+ method.getName() + "(" + Arrays.asList(args) + ")", e);
+ method.getName() + "(" + Arrays.asList(args) + ")", ex);
}
catch (InvocationTargetException e) {
catch (InvocationTargetException ex) {
logger.error("Error while invoking method " + method.getClass().getName() + "." + method.getName() + "("
+ Arrays.asList(args) + ")", e);
+ Arrays.asList(args) + ")", ex);
throw new RuntimeException("Error while invoking method " + method.getClass().getName() + "."
+ method.getName() + "(" + Arrays.asList(args) + ")", e);
+ method.getName() + "(" + Arrays.asList(args) + ")", ex);
}
}
@@ -187,14 +187,14 @@ final class DefaultWASUsernameAndGroupsExtractor implements WASUsernameAndGroups
}
return c.getDeclaredMethod(methodName, parameterTypes);
}
catch (ClassNotFoundException e) {
catch (ClassNotFoundException ex) {
logger.error("Required class" + className + " not found");
throw new RuntimeException("Required class" + className + " not found", e);
throw new RuntimeException("Required class" + className + " not found", ex);
}
catch (NoSuchMethodException e) {
catch (NoSuchMethodException ex) {
logger.error("Required method " + methodName + " with parameter types (" + Arrays.asList(parameterTypeNames)
+ ") not found on class " + className);
throw new RuntimeException("Required class" + className + " not found", e);
throw new RuntimeException("Required class" + className + " not found", ex);
}
}
@@ -242,9 +242,9 @@ final class DefaultWASUsernameAndGroupsExtractor implements WASUsernameAndGroups
try {
return Class.forName(className);
}
catch (ClassNotFoundException e) {
catch (ClassNotFoundException ex) {
logger.error("Required class " + className + " not found");
throw new RuntimeException("Required class " + className + " not found", e);
throw new RuntimeException("Required class " + className + " not found", ex);
}
}
@@ -154,8 +154,8 @@ public abstract class AbstractRememberMeServices implements RememberMeServices,
catch (AccountStatusException statusInvalid) {
this.logger.debug("Invalid UserDetails: " + statusInvalid.getMessage());
}
catch (RememberMeAuthenticationException e) {
this.logger.debug(e.getMessage());
catch (RememberMeAuthenticationException ex) {
this.logger.debug(ex.getMessage());
}
cancelCookie(request, response);
@@ -219,7 +219,7 @@ public abstract class AbstractRememberMeServices implements RememberMeServices,
try {
Base64.getDecoder().decode(cookieValue.getBytes());
}
catch (IllegalArgumentException e) {
catch (IllegalArgumentException ex) {
throw new InvalidCookieException("Cookie token was not Base64 encoded; value was '" + cookieValue + "'");
}
@@ -231,8 +231,8 @@ public abstract class AbstractRememberMeServices implements RememberMeServices,
try {
tokens[i] = URLDecoder.decode(tokens[i], StandardCharsets.UTF_8.toString());
}
catch (UnsupportedEncodingException e) {
this.logger.error(e.getMessage(), e);
catch (UnsupportedEncodingException ex) {
this.logger.error(ex.getMessage(), ex);
}
}
@@ -250,8 +250,8 @@ public abstract class AbstractRememberMeServices implements RememberMeServices,
try {
sb.append(URLEncoder.encode(cookieTokens[i], StandardCharsets.UTF_8.toString()));
}
catch (UnsupportedEncodingException e) {
this.logger.error(e.getMessage(), e);
catch (UnsupportedEncodingException ex) {
this.logger.error(ex.getMessage(), ex);
}
if (i < cookieTokens.length - 1) {
@@ -100,8 +100,8 @@ public class JdbcTokenRepositoryImpl extends JdbcDaoSupport implements Persisten
this.logger.error("Querying token for series '" + seriesId + "' returned more than one value. Series"
+ " should be unique");
}
catch (DataAccessException e) {
this.logger.error("Failed to load token for series " + seriesId, e);
catch (DataAccessException ex) {
this.logger.error("Failed to load token for series " + seriesId, ex);
}
return null;
@@ -137,8 +137,8 @@ public class PersistentTokenBasedRememberMeServices extends AbstractRememberMeSe
this.tokenRepository.updateToken(newToken.getSeries(), newToken.getTokenValue(), newToken.getDate());
addCookie(newToken, request, response);
}
catch (Exception e) {
this.logger.error("Failed to update token: ", e);
catch (Exception ex) {
this.logger.error("Failed to update token: ", ex);
throw new RememberMeAuthenticationException("Autologin failed due to data access problem");
}
@@ -163,8 +163,8 @@ public class PersistentTokenBasedRememberMeServices extends AbstractRememberMeSe
this.tokenRepository.createNewToken(persistentToken);
addCookie(persistentToken, request, response);
}
catch (Exception e) {
this.logger.error("Failed to save persistent token ", e);
catch (Exception ex) {
this.logger.error("Failed to save persistent token ", ex);
}
}
@@ -30,10 +30,10 @@ public class RememberMeAuthenticationException extends AuthenticationException {
* Constructs a {@code RememberMeAuthenticationException} with the specified message
* and root cause.
* @param msg the detail message
* @param t the root cause
* @param cause the root cause
*/
public RememberMeAuthenticationException(String msg, Throwable t) {
super(msg, t);
public RememberMeAuthenticationException(String msg, Throwable cause) {
super(msg, cause);
}
/**
@@ -148,7 +148,7 @@ public class TokenBasedRememberMeServices extends AbstractRememberMeServices {
try {
digest = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException e) {
catch (NoSuchAlgorithmException ex) {
throw new IllegalStateException("No MD5 algorithm available!");
}
@@ -177,9 +177,9 @@ public class SwitchUserFilter extends GenericFilterBean implements ApplicationEv
// redirect to target url
this.successHandler.onAuthenticationSuccess(request, response, targetUser);
}
catch (AuthenticationException e) {
this.logger.debug("Switch User failed", e);
this.failureHandler.onAuthenticationFailure(request, response, e);
catch (AuthenticationException ex) {
this.logger.debug("Switch User failed", ex);
this.failureHandler.onAuthenticationFailure(request, response, ex);
}
return;
@@ -310,7 +310,7 @@ public class SwitchUserFilter extends GenericFilterBean implements ApplicationEv
// SEC-1763. Check first if we are already switched.
currentAuth = attemptExitUser(request);
}
catch (AuthenticationCredentialsNotFoundException e) {
catch (AuthenticationCredentialsNotFoundException ex) {
currentAuth = SecurityContextHolder.getContext().getAuthentication();
}
@@ -94,7 +94,7 @@ public class BasicAuthenticationConverter implements AuthenticationConverter {
try {
decoded = Base64.getDecoder().decode(base64Token);
}
catch (IllegalArgumentException e) {
catch (IllegalArgumentException ex) {
throw new BadCredentialsException("Failed to decode basic authentication token");
}
@@ -214,7 +214,7 @@ final class DigestAuthUtils {
try {
digest = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException e) {
catch (NoSuchAlgorithmException ex) {
throw new IllegalStateException("No MD5 algorithm available!");
}
@@ -135,8 +135,8 @@ public class DigestAuthenticationFilter extends GenericFilterBean implements Mes
digestAuth.validateAndDecode(this.authenticationEntryPoint.getKey(),
this.authenticationEntryPoint.getRealmName());
}
catch (BadCredentialsException e) {
fail(request, response, e);
catch (BadCredentialsException ex) {
fail(request, response, ex);
return;
}
@@ -374,7 +374,7 @@ public class DigestAuthenticationFilter extends GenericFilterBean implements Mes
try {
Base64.getDecoder().decode(this.nonce.getBytes());
}
catch (IllegalArgumentException e) {
catch (IllegalArgumentException ex) {
throw new BadCredentialsException(
DigestAuthenticationFilter.this.messages.getMessage("DigestAuthenticationFilter.nonceEncoding",
new Object[] { this.nonce }, "Nonce is not encoded in Base64; received nonce {0}"));
@@ -37,10 +37,10 @@ public class NonceExpiredException extends AuthenticationException {
* Constructs a <code>NonceExpiredException</code> with the specified message and root
* cause.
* @param msg the detail message
* @param t root cause
* @param cause root cause
*/
public NonceExpiredException(String msg, Throwable t) {
super(msg, t);
public NonceExpiredException(String msg, Throwable cause) {
super(msg, cause);
}
}
@@ -437,7 +437,7 @@ public class HttpSessionSecurityContextRepository implements SecurityContextRepo
try {
return this.request.getSession(true);
}
catch (IllegalStateException e) {
catch (IllegalStateException ex) {
// Response must already be committed, therefore can't create a new
// session
HttpSessionSecurityContextRepository.this.logger
@@ -414,8 +414,8 @@ public final class HpkpHeaderWriter implements HeaderWriter {
try {
this.reportUri = new URI(reportUri);
}
catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
catch (URISyntaxException ex) {
throw new IllegalArgumentException(ex);
}
updateHpkpHeaderValue();
}
@@ -98,8 +98,8 @@ public class JaasApiIntegrationFilter extends GenericFilterBean {
try {
Subject.doAs(subject, continueChain);
}
catch (PrivilegedActionException e) {
throw new ServletException(e.getMessage(), e);
catch (PrivilegedActionException ex) {
throw new ServletException(ex.getMessage(), ex);
}
}
@@ -59,7 +59,7 @@ public class DelegatingServerAuthenticationEntryPoint implements ServerAuthentic
}
@Override
public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException e) {
public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException ex) {
return Flux.fromIterable(this.entryPoints).filterWhen(entry -> isMatch(exchange, entry)).next()
.map(entry -> entry.getEntryPoint()).doOnNext(it -> {
if (logger.isDebugEnabled()) {
@@ -69,7 +69,7 @@ public class DelegatingServerAuthenticationEntryPoint implements ServerAuthentic
if (logger.isDebugEnabled()) {
logger.debug("No match found. Using default entry point " + this.defaultEntryPoint);
}
})).flatMap(entryPoint -> entryPoint.commence(exchange, e));
})).flatMap(entryPoint -> entryPoint.commence(exchange, ex));
}
private Mono<Boolean> isMatch(ServerWebExchange exchange, DelegateEntry entry) {
@@ -32,10 +32,10 @@ public interface ServerAuthenticationEntryPoint {
/**
* Initiates the authentication flow
* @param exchange
* @param e
* @param ex
* @return {@code Mono<Void>} to indicate when the request for authentication is
* complete
*/
Mono<Void> commence(ServerWebExchange exchange, AuthenticationException e);
Mono<Void> commence(ServerWebExchange exchange, AuthenticationException ex);
}
@@ -72,7 +72,7 @@ public class ServerHttpBasicAuthenticationConverter implements Function<ServerWe
try {
return Base64.getDecoder().decode(value);
}
catch (Exception e) {
catch (Exception ex) {
return new byte[0];
}
}
@@ -41,7 +41,7 @@ public class HttpBasicServerAuthenticationEntryPoint implements ServerAuthentica
private String headerValue = createHeaderValue(DEFAULT_REALM);
@Override
public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException e) {
public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException ex) {
return Mono.fromRunnable(() -> {
ServerHttpResponse response = exchange.getResponse();
response.setStatusCode(HttpStatus.UNAUTHORIZED);
@@ -62,7 +62,7 @@ public class RedirectServerAuthenticationEntryPoint implements ServerAuthenticat
}
@Override
public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException e) {
public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException ex) {
return this.requestCache.saveRequest(exchange)
.then(this.redirectStrategy.sendRedirect(exchange, this.location));
}
@@ -49,12 +49,12 @@ public class HttpStatusServerAccessDeniedHandler implements ServerAccessDeniedHa
}
@Override
public Mono<Void> handle(ServerWebExchange exchange, AccessDeniedException e) {
public Mono<Void> handle(ServerWebExchange exchange, AccessDeniedException ex) {
return Mono.defer(() -> Mono.just(exchange.getResponse())).flatMap(response -> {
response.setStatusCode(this.httpStatus);
response.getHeaders().setContentType(MediaType.TEXT_PLAIN);
DataBufferFactory dataBufferFactory = response.bufferFactory();
DataBuffer buffer = dataBufferFactory.wrap(e.getMessage().getBytes(Charset.defaultCharset()));
DataBuffer buffer = dataBufferFactory.wrap(ex.getMessage().getBytes(Charset.defaultCharset()));
return response.writeWith(Mono.just(buffer)).doOnError(error -> DataBufferUtils.release(buffer));
});
}
@@ -76,8 +76,8 @@ public class MediaTypeServerWebExchangeMatcher implements ServerWebExchangeMatch
try {
httpRequestMediaTypes = resolveMediaTypes(exchange);
}
catch (NotAcceptableStatusException e) {
this.logger.debug("Failed to parse MediaTypes, returning false", e);
catch (NotAcceptableStatusException ex) {
this.logger.debug("Failed to parse MediaTypes, returning false", ex);
return MatchResult.notMatch();
}
if (this.logger.isDebugEnabled()) {
@@ -82,7 +82,7 @@ public class MvcRequestMatcher implements RequestMatcher, RequestVariablesExtrac
try {
return this.introspector.getMatchableHandlerMapping(request);
}
catch (Throwable t) {
catch (Throwable ex) {
return null;
}
}
@@ -95,11 +95,11 @@ public class SessionManagementFilter extends GenericFilterBean {
try {
this.sessionAuthenticationStrategy.onAuthentication(authentication, request, response);
}
catch (SessionAuthenticationException e) {
catch (SessionAuthenticationException ex) {
// The session strategy can reject the authentication
this.logger.debug("SessionAuthenticationStrategy rejected the authentication object", e);
this.logger.debug("SessionAuthenticationStrategy rejected the authentication object", ex);
SecurityContextHolder.clearContext();
this.failureHandler.onAuthenticationFailure(request, response, e);
this.failureHandler.onAuthenticationFailure(request, response, ex);
return;
}
@@ -249,7 +249,7 @@ public final class AntPathRequestMatcher implements RequestMatcher, RequestVaria
try {
return HttpMethod.valueOf(method);
}
catch (IllegalArgumentException e) {
catch (IllegalArgumentException ex) {
}
return null;
@@ -101,8 +101,8 @@ public final class IpAddressMatcher implements RequestMatcher {
try {
return InetAddress.getByName(address);
}
catch (UnknownHostException e) {
throw new IllegalArgumentException("Failed to parse address" + address, e);
catch (UnknownHostException ex) {
throw new IllegalArgumentException("Failed to parse address" + address, ex);
}
}
@@ -201,8 +201,8 @@ public final class MediaTypeRequestMatcher implements RequestMatcher {
try {
httpRequestMediaTypes = this.contentNegotiationStrategy.resolveMediaTypes(new ServletWebRequest(request));
}
catch (HttpMediaTypeNotAcceptableException e) {
this.logger.debug("Failed to parse MediaTypes, returning false", e);
catch (HttpMediaTypeNotAcceptableException ex) {
this.logger.debug("Failed to parse MediaTypes, returning false", ex);
return false;
}
if (this.logger.isDebugEnabled()) {
@@ -120,7 +120,7 @@ public final class RegexRequestMatcher implements RequestMatcher {
try {
return HttpMethod.valueOf(method);
}
catch (IllegalArgumentException e) {
catch (IllegalArgumentException ex) {
}
return null;
@@ -240,11 +240,11 @@ public class AuthenticationFilterTests {
try {
filter.doFilter(request, response, chain);
}
catch (ServletException e) {
catch (ServletException ex) {
verifyZeroInteractions(this.successHandler);
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
throw e;
throw ex;
}
}
@@ -129,7 +129,7 @@ public class UsernamePasswordAuthenticationFilterTests {
filter.attemptAuthentication(request, new MockHttpServletResponse());
fail("Expected AuthenticationException");
}
catch (AuthenticationException e) {
catch (AuthenticationException ex) {
}
}
@@ -69,8 +69,8 @@ public class HttpStatusReturningLogoutSuccessHandlerTests {
try {
new HttpStatusReturningLogoutSuccessHandler(null);
}
catch (IllegalArgumentException e) {
assertThat(e).hasMessage("The provided HttpStatus must not be null.");
catch (IllegalArgumentException ex) {
assertThat(ex).hasMessage("The provided HttpStatus must not be null.");
return;
}
@@ -38,8 +38,8 @@ public class Http403ForbiddenEntryPointTests {
assertThat(resp.getStatus()).withFailMessage("Incorrect status")
.isEqualTo(HttpServletResponse.SC_FORBIDDEN);
}
catch (IOException e) {
fail("Unexpected exception thrown: " + e);
catch (IOException ex) {
fail("Unexpected exception thrown: " + ex);
}
}
@@ -96,7 +96,7 @@ public class ThrowableAnalyzerTests {
fail("IllegalArgumentExpected");
}
catch (IllegalArgumentException e) {
catch (IllegalArgumentException ex) {
// ok
}
}
@@ -231,7 +231,7 @@ public class ThrowableAnalyzerTests {
ThrowableAnalyzer.verifyThrowableHierarchy(null, Throwable.class);
fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException e) {
catch (IllegalArgumentException ex) {
// ok
}
}
@@ -244,7 +244,7 @@ public class ThrowableAnalyzerTests {
ThrowableAnalyzer.verifyThrowableHierarchy(throwable, InvocationTargetException.class);
fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException e) {
catch (IllegalArgumentException ex) {
// ok
}
}