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

@@ -1223,8 +1223,7 @@ public class HttpHeaders implements Serializable {
try {
port = Integer.parseInt(portString);
}
catch (NumberFormatException ex) {
// ignore
catch (NumberFormatException ignored) {
}
}

View File

@@ -89,8 +89,7 @@ final class HttpComponentsClientHttpResponse implements ClientHttpResponse {
this.httpResponse.close();
}
}
catch (IOException ex) {
// Ignore exception on close...
catch (IOException ignored) {
}
}

View File

@@ -108,8 +108,7 @@ final class ReactorClientHttpResponse implements ClientHttpResponse {
StreamUtils.drain(body);
body.close();
}
catch (IOException ex) {
// ignore
catch (IOException ignored) {
}
}

View File

@@ -119,8 +119,7 @@ class HttpComponentsClientHttpResponse extends AbstractClientHttpResponse {
ZonedDateTime expiresDate = ZonedDateTime.parse(expiresAttribute, DateTimeFormatter.RFC_1123_DATE_TIME);
return Duration.between(ZonedDateTime.now(expiresDate.getZone()), expiresDate).toSeconds();
}
catch (DateTimeParseException ex) {
// ignore
catch (DateTimeParseException ignored) {
}
}
return -1;

View File

@@ -158,20 +158,20 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<R
in.transferTo(out);
out.flush();
}
catch (NullPointerException ex) {
// ignore, see SPR-13620
catch (NullPointerException ignored) {
// see SPR-13620
}
finally {
try {
in.close();
}
catch (Throwable ex) {
// ignore, see SPR-12999
catch (Throwable ignored) {
// see SPR-12999
}
}
}
catch (FileNotFoundException ex) {
// ignore, see SPR-12999
catch (FileNotFoundException ignored) {
// see SPR-12999
}
}

View File

@@ -183,8 +183,7 @@ public class ResourceRegionHttpMessageConverter extends AbstractGenericHttpMessa
try {
in.close();
}
catch (IOException ex) {
// ignore
catch (IOException ignored) {
}
}
}
@@ -244,8 +243,7 @@ public class ResourceRegionHttpMessageConverter extends AbstractGenericHttpMessa
in.close();
}
}
catch (IOException ex) {
// ignore
catch (IOException ignored) {
}
}

View File

@@ -270,8 +270,7 @@ public class SourceHttpMessageConverter<T extends Source> extends AbstractHttpMe
transform(t, new StreamResult(os));
return os.count;
}
catch (TransformerException ex) {
// ignore
catch (TransformerException ignored) {
}
}
return null;

View File

@@ -439,8 +439,7 @@ public abstract class AbstractListenerWriteProcessor<T> implements Processor<T,
// ignore
}
@Override
public <T> void onError(AbstractListenerWriteProcessor<T> processor, Throwable ex) {
// ignore
public <T> void onError(AbstractListenerWriteProcessor<T> processor, Throwable ignored) {
}
@Override
public <T> void onComplete(AbstractListenerWriteProcessor<T> processor) {

View File

@@ -309,8 +309,7 @@ public class ServletHttpHandlerAdapter implements Servlet {
try {
listener.onTimeout(event);
}
catch (Exception ex) {
// Ignore
catch (Exception ignored) {
}
}
@@ -318,8 +317,7 @@ public class ServletHttpHandlerAdapter implements Servlet {
try {
listener.onError(event);
}
catch (Exception ex) {
// Ignore
catch (Exception ignored) {
}
}
@@ -327,8 +325,7 @@ public class ServletHttpHandlerAdapter implements Servlet {
try {
listener.onComplete(event);
}
catch (Exception ex) {
// Ignore
catch (Exception ignored) {
}
}

View File

@@ -152,8 +152,7 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
try {
return FileCopyUtils.copyToByteArray(response.getBody());
}
catch (IOException ex) {
// ignore
catch (IOException ignored) {
}
return new byte[0];
}

View File

@@ -113,8 +113,7 @@ class CallableInterceptorChain {
try {
future.cancel(true);
}
catch (Throwable ex) {
// Ignore
catch (Throwable ignored) {
}
}
}

View File

@@ -235,8 +235,7 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements
break;
}
}
catch (InterruptedException ex) {
// ignore
catch (InterruptedException ignored) {
}
}

View File

@@ -122,8 +122,7 @@ public class ServletContextResource extends AbstractFileResolvingResource implem
try {
is.close();
}
catch (IOException ex) {
// ignore
catch (IOException ignored) {
}
return true;
}

View File

@@ -151,8 +151,7 @@ public final class HttpServiceProxyRegistryFactoryBean
Class<?> clazz = ClassUtils.forName(className, HttpServiceGroupAdapter.class.getClassLoader());
groupAdapters.put(clientType, (HttpServiceGroupAdapter<?>) BeanUtils.instantiateClass(clazz));
}
catch (ClassNotFoundException ex) {
// ignore
catch (ClassNotFoundException ignored) {
}
}
}

View File

@@ -93,7 +93,7 @@ class RequestContextListenerTests {
try {
thread.join();
}
catch (InterruptedException ex) {
catch (InterruptedException ignored) {
}
// Still bound to original thread, but at least completed.
assertThat(RequestContextHolder.getRequestAttributes()).isNotNull();

View File

@@ -100,8 +100,7 @@ public class MockClientHttpResponse extends MockHttpInputMessage implements Clie
try {
getBody().close();
}
catch (IOException ex) {
// ignore
catch (IOException ignored) {
}
}

View File

@@ -1128,8 +1128,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
try {
return simpleDateFormat.parse(value).getTime();
}
catch (ParseException ex) {
// ignore
catch (ParseException ignored) {
}
}
throw new IllegalArgumentException("Cannot parse date value '" + value + "' for '" + name + "' header");