Skip to content

Commit 0d4dfb6

Browse files
Vincent Potucekbclozel
authored andcommitted
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 <[email protected]> [[email protected]: rework commit message] Signed-off-by: Brian Clozel <[email protected]>
1 parent cd3ac44 commit 0d4dfb6

File tree

46 files changed

+66
-108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+66
-108
lines changed

integration-tests/src/test/java/org/springframework/aop/framework/autoproxy/AdvisorAutoProxyCreatorIntegrationTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ void testRollbackRulesOnMethodPreventRollback() throws Exception {
158158
try {
159159
rb.echoException(new ServletException());
160160
}
161-
catch (ServletException ex) {
162-
161+
catch (ServletException ignored) {
163162
}
164163
assertThat(txMan.commits).as("Transaction counts match").isEqualTo(1);
165164
}
@@ -272,7 +271,7 @@ public void before(Method method, Object[] args, Object target) throws Throwable
272271
TransactionInterceptor.currentTransactionStatus();
273272
throw new RuntimeException("Shouldn't have a transaction");
274273
}
275-
catch (NoTransactionException ex) {
274+
catch (NoTransactionException ignored) {
276275
// this is Ok
277276
}
278277
}

spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,9 @@ private ShadowMatch getTargetShadowMatch(Method method, Class<?> targetClass) {
453453
ClassUtils.toClassArray(ifcs), targetClass.getClassLoader());
454454
targetMethod = ClassUtils.getMostSpecificMethod(targetMethod, compositeInterface);
455455
}
456-
catch (IllegalArgumentException ex) {
457-
// Implemented interfaces probably expose conflicting method signatures...
458-
// Proceed with original target method.
456+
// Implemented interfaces probably expose conflicting method signatures...
457+
// Proceed with original target method.
458+
catch (IllegalArgumentException ignored) {
459459
}
460460
}
461461
}
@@ -478,7 +478,7 @@ private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) {
478478
try {
479479
shadowMatch = pointcutExpression.matchesMethodExecution(methodToMatch);
480480
}
481-
catch (ReflectionWorldException ex) {
481+
catch (ReflectionWorldException ignored) {
482482
// Failed to introspect target method, probably because it has been loaded
483483
// in a special ClassLoader. Let's try the declaring ClassLoader instead...
484484
try {
@@ -501,7 +501,7 @@ private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) {
501501
try {
502502
shadowMatch = pointcutExpression.matchesMethodExecution(methodToMatch);
503503
}
504-
catch (ReflectionWorldException ex) {
504+
catch (ReflectionWorldException ignored) {
505505
// Could neither introspect the target class nor the proxy class ->
506506
// let's try the original method's declaring class before we give up...
507507
try {

spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ public static boolean isQualifierMatch(
208208
}
209209
}
210210
}
211-
catch (NoSuchBeanDefinitionException ex) {
212-
// Ignore - can't compare qualifiers for a manually registered singleton object
211+
catch (NoSuchBeanDefinitionException ignored) {
212+
// can't compare qualifiers for a manually registered singleton object
213213
}
214214
}
215215
return false;

spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,7 @@ private void resolveTypeStringValue(TypedStringValue typedStringValue) {
523523
try {
524524
typedStringValue.resolveTargetType(this.beanFactory.getBeanClassLoader());
525525
}
526-
catch (ClassNotFoundException ex) {
527-
// ignore
526+
catch (ClassNotFoundException ignored) {
528527
}
529528
}
530529

spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ public void afterPropertiesSet() {
266266
Method eclMethod = configuration.getClass().getMethod("externalClassLoader", ClassLoader.class);
267267
ReflectionUtils.invokeMethod(eclMethod, configuration, this.applicationContext.getClassLoader());
268268
}
269-
catch (NoSuchMethodException ex) {
270-
// Ignore - no Hibernate Validator 5.2+ or similar provider
269+
catch (NoSuchMethodException ignored) {
270+
// no Hibernate Validator 5.2+ or similar provider
271271
}
272272
}
273273

@@ -417,8 +417,8 @@ public <T> T unwrap(@Nullable Class<T> type) {
417417
try {
418418
return super.unwrap(type);
419419
}
420-
catch (ValidationException ex) {
421-
// Ignore - we'll try ValidatorFactory unwrapping next
420+
catch (ValidationException ignored) {
421+
// we'll try ValidatorFactory unwrapping next
422422
}
423423
}
424424
if (this.validatorFactory != null) {

spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ void serializableTargetAndAdvice() throws Throwable {
233233
try {
234234
p2.echo(new IOException());
235235
}
236-
catch (IOException ex) {
237-
236+
catch (IOException ignored) {
238237
}
239238
assertThat(cta.getCalls()).isEqualTo(2);
240239
}

spring-core-test/src/main/java/org/springframework/core/test/tools/CompileWithForkedClassLoaderClassLoader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
8484
try (stream) {
8585
return stream.readAllBytes();
8686
}
87-
catch (IOException ex) {
88-
// ignore
87+
catch (IOException ignored) {
8988
}
9089
}
9190
return null;

spring-core/src/main/java/org/springframework/cglib/proxy/BridgeMethodResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public BridgeMethodResolver(Map declToBridge, ClassLoader classLoader) {
7373
} finally {
7474
is.close();
7575
}
76-
} catch (IOException ignored) {}
76+
} catch (IOException ignored) {
77+
}
7778
}
7879
return resolved;
7980
}

spring-core/src/main/java/org/springframework/cglib/proxy/MethodProxy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public static MethodProxy create(Class c1, Class c2, String desc, String name1,
6262
try {
6363
proxy.init();
6464
}
65-
catch (CodeGenerationException ex) {
66-
// Ignore - to be retried when actually needed later on (possibly not at all)
65+
catch (CodeGenerationException ignored) {
66+
// to be retried when actually needed later on (possibly not at all)
6767
}
6868
}
6969
// SPRING PATCH END

spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,7 @@ private static class KotlinDelegate {
438438
return constructor;
439439
}
440440
}
441-
catch (UnsupportedOperationException ex) {
442-
// ignore
441+
catch (UnsupportedOperationException ignored) {
443442
}
444443
return null;
445444
}

0 commit comments

Comments
 (0)