Rename exception variables in empty catch blocks

The Spring codebase sometimes ignores exceptions in catch blocks on
purpose. This is often called out by an inline comment.
We should make this more obvious by renaming the exception argument in
the catch block to declare whether the exception is "ignored" or
"expected".

See gh-35047

Signed-off-by: Vincent Potucek <vpotucek@me.com>
[brian.clozel@broadcom.com: rework commit message]
Signed-off-by: Brian Clozel <brian.clozel@broadcom.com>
This commit is contained in:
Vincent Potucek
2025-06-13 16:03:24 +02:00
committed by Brian Clozel
parent cd3ac44fb0
commit 0d4dfb6c1f
46 changed files with 66 additions and 108 deletions

View File

@@ -622,8 +622,7 @@ public class MvcUriComponentsBuilder {
try {
return wac.getBean(MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME, CompositeUriComponentsContributor.class);
}
catch (NoSuchBeanDefinitionException ex) {
// Ignore
catch (NoSuchBeanDefinitionException ignored) {
}
}
return defaultUriComponentsContributor;

View File

@@ -788,8 +788,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
return getBeanFactory().getBean(
DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, LocaleResolver.class);
}
catch (NoSuchBeanDefinitionException ex) {
// ignore
catch (NoSuchBeanDefinitionException ignored) {
}
}
return null;

View File

@@ -191,8 +191,7 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM
try {
body.close();
}
catch (IOException ex) {
// ignore
catch (IOException ignored) {
}
}

View File

@@ -77,8 +77,7 @@ public abstract class ResourceHandlerUtils {
Assert.isTrue(path.endsWith(FOLDER_SEPARATOR) || path.endsWith(WINDOWS_FOLDER_SEPARATOR),
"Resource location does not end with slash: " + path);
}
catch (IOException ex) {
// ignore
catch (IOException ignored) {
}
}

View File

@@ -611,8 +611,7 @@ class ExceptionHandlerExceptionResolverTests {
@ExceptionHandler(SocketTimeoutException.class)
@ResponseStatus(code = HttpStatus.GATEWAY_TIMEOUT, reason = "gateway.timeout")
public void handleException(SocketTimeoutException ex) {
public void handleException(SocketTimeoutException ignored) {
}
}