Skip to content

Commit 5778dec

Browse files
jxblummp911de
authored andcommitted
Apply consistent Exception variable names to all catch blocks.
We now consistently align with the core Spring Framework's use of 'ex' as the variable name for Exceptions handled in catch blocks, and 'ignore' for all Exceptions thrown, but ignored by framework code. Both 'ex' and 'ignore' were appropriately used based on the context and nautre of the Exception handler in the catch block. Additionally, we use the 'expected' variable name for Exception thrown in tests where the thrown Exception is the expected outcome of the test case. Only 1 exception exists to these name conventions, and that is 'nested', which was necessarily used in ScanCursor due to the nested try-catch blocks. Applied consistent use of String.format(..) to Exception messages requiring formatting. Formatted catch block according to source code formatting style. Closes #2748 Original pull request: #2749
1 parent 89229af commit 5778dec

File tree

66 files changed

+284
-284
lines changed

Some content is hidden

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

66 files changed

+284
-284
lines changed

src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ private void checkAndPotentiallyWaitUntilUnlocked(String name, RedisConnection c
307307
// Re-interrupt current thread, to allow other participants to react.
308308
Thread.currentThread().interrupt();
309309

310-
throw new PessimisticLockingFailureException(String.format("Interrupted while waiting to unlock cache %s", name),
311-
ex);
310+
String message = String.format("Interrupted while waiting to unlock cache %s", name);
311+
312+
throw new PessimisticLockingFailureException(message, ex);
312313
} finally {
313314
statistics.incLockTime(name, System.nanoTime() - lockWaitTimeNs);
314315
}

src/main/java/org/springframework/data/redis/cache/RedisCache.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ protected <T> T loadCacheValue(Object key, Callable<T> valueLoader) {
152152

153153
try {
154154
value = valueLoader.call();
155-
} catch (Exception cause) {
156-
throw new ValueRetrievalException(key, valueLoader, cause);
155+
} catch (Exception ex) {
156+
throw new ValueRetrievalException(key, valueLoader, ex);
157157
}
158158

159159
put(key, value);
@@ -327,14 +327,14 @@ protected String convertKey(Object key) {
327327
if (conversionService.canConvert(source, TypeDescriptor.valueOf(String.class))) {
328328
try {
329329
return conversionService.convert(key, String.class);
330-
} catch (ConversionFailedException cause) {
330+
} catch (ConversionFailedException ex) {
331331

332332
// May fail if the given key is a collection
333333
if (isCollectionLikeOrMap(source)) {
334334
return convertCollectionLikeOrMapKey(key, source);
335335
}
336336

337-
throw cause;
337+
throw ex;
338338
}
339339
}
340340

src/main/java/org/springframework/data/redis/connection/AbstractRedisConnection.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public void close() throws DataAccessException {
114114

115115
try {
116116
connection.close();
117-
} catch (IOException e) {
118-
LOGGER.info("Failed to close sentinel connection", e);
117+
} catch (IOException ex) {
118+
LOGGER.info("Failed to close sentinel connection", ex);
119119
}
120120
}
121121
}

src/main/java/org/springframework/data/redis/connection/RedisNode.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static RedisNode fromString(String hostPortString) {
101101
int port = -1;
102102
try {
103103
port = Integer.parseInt(portString);
104-
} catch (RuntimeException e) {
104+
} catch (RuntimeException ignore) {
105105
throw new IllegalArgumentException(String.format("Unparseable port number: %s", hostPortString));
106106
}
107107

src/main/java/org/springframework/data/redis/connection/convert/Converters.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ public static Properties toProperties(String source) {
109109

110110
try (StringReader stringReader = new StringReader(source)) {
111111
info.load(stringReader);
112-
} catch (Exception cause) {
113-
throw new RedisSystemException("Cannot read Redis info", cause);
112+
} catch (Exception ex) {
113+
throw new RedisSystemException("Cannot read Redis info", ex);
114114
}
115115

116116
return info;

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ public JedisClusterConnection(JedisCluster cluster) {
123123
Object custerCommandExecutor = executorDfa.getPropertyValue("executor");
124124
DirectFieldAccessor dfa = new DirectFieldAccessor(custerCommandExecutor);
125125
clusterCommandExecutor.setMaxRedirects((Integer) dfa.getPropertyValue("maxRedirects"));
126-
} catch (Exception e) {
127-
// ignore it and work with the executor default
126+
} catch (Exception ignore) {
127+
// ignore and work with the executor default
128128
}
129129
}
130130

@@ -381,8 +381,8 @@ public void subscribe(MessageListener listener, byte[]... channels) {
381381
JedisMessageListener jedisPubSub = new JedisMessageListener(listener);
382382
subscription = new JedisSubscription(listener, jedisPubSub, channels, null);
383383
cluster.subscribe(jedisPubSub, channels);
384-
} catch (Exception cause) {
385-
throw convertJedisAccessException(cause);
384+
} catch (Exception ex) {
385+
throw convertJedisAccessException(ex);
386386
}
387387
}
388388

@@ -398,8 +398,8 @@ public void pSubscribe(MessageListener listener, byte[]... patterns) {
398398
JedisMessageListener jedisPubSub = new JedisMessageListener(listener);
399399
subscription = new JedisSubscription(listener, jedisPubSub, null, patterns);
400400
cluster.psubscribe(jedisPubSub, patterns);
401-
} catch (Exception cause) {
402-
throw convertJedisAccessException(cause);
401+
} catch (Exception ex) {
402+
throw convertJedisAccessException(ex);
403403
}
404404
}
405405

@@ -643,8 +643,8 @@ public void close() throws DataAccessException {
643643
if (!closed && disposeClusterCommandExecutorOnClose) {
644644
try {
645645
clusterCommandExecutor.destroy();
646-
} catch (Exception cause) {
647-
log.warn("Cannot properly close cluster command executor", cause);
646+
} catch (Exception ex) {
647+
log.warn("Cannot properly close cluster command executor", ex);
648648
}
649649
}
650650

src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -405,17 +405,17 @@ private List<Object> convertPipelineResults() {
405405
if (!result.isStatus()) {
406406
results.add(result.conversionRequired() ? result.convert(data) : data);
407407
}
408-
} catch (JedisDataException e) {
409-
DataAccessException dataAccessException = convertJedisAccessException(e);
408+
} catch (JedisDataException ex) {
409+
DataAccessException dataAccessException = convertJedisAccessException(ex);
410410
if (cause == null) {
411411
cause = dataAccessException;
412412
}
413413
results.add(dataAccessException);
414-
} catch (DataAccessException e) {
414+
} catch (DataAccessException ex) {
415415
if (cause == null) {
416-
cause = e;
416+
cause = ex;
417417
}
418-
results.add(e);
418+
results.add(ex);
419419
}
420420
}
421421
if (cause != null) {
@@ -670,7 +670,7 @@ protected boolean isActive(RedisNode node) {
670670
verification = getJedis(node);
671671
verification.connect();
672672
return verification.ping().equalsIgnoreCase("pong");
673-
} catch (Exception e) {
673+
} catch (Exception ignore) {
674674
return false;
675675
} finally {
676676
if (verification != null) {

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnection.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ public Long clusterCountKeysInSlot(int slot) {
380380

381381
try {
382382
return getConnection().clusterCountKeysInSlot(slot);
383-
} catch (Exception cause) {
384-
throw this.exceptionConverter.translate(cause);
383+
} catch (Exception ex) {
384+
throw this.exceptionConverter.translate(ex);
385385
}
386386
}
387387

@@ -451,8 +451,8 @@ public List<byte[]> clusterGetKeysInSlot(int slot, Integer count) {
451451

452452
try {
453453
return getConnection().clusterGetKeysInSlot(slot, count);
454-
} catch (Exception cause) {
455-
throw this.exceptionConverter.translate(cause);
454+
} catch (Exception ex) {
455+
throw this.exceptionConverter.translate(ex);
456456
}
457457
}
458458

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java

+15-14
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ public void close() {
366366

367367
try {
368368
reset();
369-
} catch (RuntimeException e) {
370-
LOGGER.debug("Failed to reset connection during close", e);
369+
} catch (RuntimeException ex) {
370+
LOGGER.debug("Failed to reset connection during close", ex);
371371
}
372372
}
373373

@@ -468,11 +468,11 @@ public List<Object> closePipeline() {
468468

469469
try {
470470
results.add(result.conversionRequired() ? result.convert(result.get()) : result.get());
471-
} catch (DataAccessException e) {
471+
} catch (DataAccessException ex) {
472472
if (problem == null) {
473-
problem = e;
473+
problem = ex;
474474
}
475-
results.add(e);
475+
results.add(ex);
476476
}
477477
}
478478
}
@@ -488,8 +488,8 @@ public List<Object> closePipeline() {
488488
}
489489

490490
throw new RedisPipelineException(new QueryTimeoutException("Redis command timed out"));
491-
} catch (Exception e) {
492-
throw new RedisPipelineException(e);
491+
} catch (Exception ex) {
492+
throw new RedisPipelineException(ex);
493493
}
494494
}
495495

@@ -573,7 +573,7 @@ public void select(int dbIndex) {
573573

574574
if (asyncSharedConn != null) {
575575
throw new InvalidDataAccessApiUsageException("Selecting a new database not supported due to shared connection;"
576-
+ " Use separate ConnectionFactorys to work with multiple databases");
576+
+ " Use separate ConnectionFactory instances to work with multiple databases");
577577
}
578578

579579
this.dbIndex = dbIndex;
@@ -930,7 +930,7 @@ protected boolean isActive(RedisNode node) {
930930
try {
931931
connection = getConnection(node);
932932
return connection.sync().ping().equalsIgnoreCase("pong");
933-
} catch (Exception e) {
933+
} catch (Exception ignore) {
934934
return false;
935935
} finally {
936936
if (connection != null) {
@@ -965,8 +965,8 @@ private <T> T await(RedisFuture<T> cmd) {
965965

966966
try {
967967
return LettuceFutures.awaitOrCancel(cmd, timeout, TimeUnit.MILLISECONDS);
968-
} catch (RuntimeException e) {
969-
throw convertLettuceAccessException(e);
968+
} catch (RuntimeException ex) {
969+
throw convertLettuceAccessException(ex);
970970
}
971971
}
972972

@@ -1031,8 +1031,9 @@ private void validateCommand(ProtocolKeyword cmd, @Nullable byte[]... args) {
10311031
if (!RedisCommand.UNKNOWN.equals(redisCommand) && redisCommand.requiresArguments()) {
10321032
try {
10331033
redisCommand.validateArgumentCount(args != null ? args.length : 0);
1034-
} catch (IllegalArgumentException e) {
1035-
throw new InvalidDataAccessApiUsageException(String.format("Validation failed for %s command", cmd), e);
1034+
} catch (IllegalArgumentException ex) {
1035+
String message = String.format("Validation failed for %s command", command);
1036+
throw new InvalidDataAccessApiUsageException(message, ex);
10361037
}
10371038
}
10381039
}
@@ -1041,7 +1042,7 @@ private static ProtocolKeyword getCommandType(String name) {
10411042

10421043
try {
10431044
return CommandType.valueOf(name);
1044-
} catch (IllegalArgumentException e) {
1045+
} catch (IllegalArgumentException ignore) {
10451046
return new CustomCommandType(name);
10461047
}
10471048
}

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1380,8 +1380,8 @@ void validateConnection() {
13801380
((StatefulRedisClusterConnection) connection).sync().ping();
13811381
}
13821382
valid = true;
1383-
} catch (Exception e) {
1384-
log.debug("Validation failed", e);
1383+
} catch (Exception ex) {
1384+
log.debug("Validation failed", ex);
13851385
}
13861386
}
13871387

@@ -1531,8 +1531,8 @@ public ExceptionTranslatingConnectionProvider(LettuceConnectionProvider delegate
15311531

15321532
try {
15331533
return delegate.getConnection(connectionType);
1534-
} catch (RuntimeException e) {
1535-
throw translateException(e);
1534+
} catch (RuntimeException ex) {
1535+
throw translateException(ex);
15361536
}
15371537
}
15381538

@@ -1541,8 +1541,8 @@ public ExceptionTranslatingConnectionProvider(LettuceConnectionProvider delegate
15411541

15421542
try {
15431543
return ((TargetAware) delegate).getConnection(connectionType, redisURI);
1544-
} catch (RuntimeException e) {
1545-
throw translateException(e);
1544+
} catch (RuntimeException ex) {
1545+
throw translateException(ex);
15461546
}
15471547
}
15481548

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceFutureUtils.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ static <T> T join(CompletionStage<T> future) throws RuntimeException, Completion
6666

6767
try {
6868
return future.toCompletableFuture().join();
69-
} catch (Exception e) {
69+
} catch (Exception ex) {
7070

71-
Throwable exceptionToUse = e;
71+
Throwable exceptionToUse = ex;
7272

73-
if (e instanceof CompletionException) {
74-
exceptionToUse = LettuceExceptionConverter.INSTANCE.convert((Exception) e.getCause());
73+
if (ex instanceof CompletionException) {
74+
exceptionToUse = LettuceExceptionConverter.INSTANCE.convert((Exception) ex.getCause());
7575
if (exceptionToUse == null) {
76-
exceptionToUse = e.getCause();
76+
exceptionToUse = ex.getCause();
7777
}
7878
}
7979

src/main/java/org/springframework/data/redis/connection/lettuce/LettucePoolingConnectionProvider.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class LettucePoolingConnectionProvider implements LettuceConnectionProvider, Red
100100

101101
poolRef.put(connection, pool);
102102
return connectionType.cast(connection);
103-
} catch (Exception e) {
104-
throw new PoolException("Could not get a resource from the pool", e);
103+
} catch (Exception ex) {
104+
throw new PoolException("Could not get a resource from the pool", ex);
105105
}
106106
}
107107

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelConnection.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ public void failover(NamedNode master) {
158158
public List<RedisServer> masters() {
159159
try {
160160
return LettuceConverters.toListOfRedisServer(getSentinelCommands().masters());
161-
} catch (Exception e) {
162-
throw EXCEPTION_TRANSLATION.translate(e);
161+
} catch (Exception ex) {
162+
throw EXCEPTION_TRANSLATION.translate(ex);
163163
}
164164
}
165165

@@ -180,8 +180,8 @@ public List<RedisServer> slaves(String masterName) {
180180
Assert.hasText(masterName, "Name of redis master cannot be 'null' or empty when loading replicas.");
181181
try {
182182
return LettuceConverters.toListOfRedisServer(getSentinelCommands().slaves(masterName));
183-
} catch (Exception e) {
184-
throw EXCEPTION_TRANSLATION.translate(e);
183+
} catch (Exception ex) {
184+
throw EXCEPTION_TRANSLATION.translate(ex);
185185
}
186186
}
187187

src/main/java/org/springframework/data/redis/connection/lettuce/StreamConverters.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private static Object preConvertNativeValues(@Nullable Object value) {
140140

141141
try {
142142
return NumberUtils.parseNumber(tmp, Long.class);
143-
} catch (NumberFormatException e) {
143+
} catch (NumberFormatException ex) {
144144
return tmp;
145145
}
146146
}

src/main/java/org/springframework/data/redis/core/BoundOperationsProxyFactory.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ private Object doInvoke(MethodInvocation invocation, Method method, Object targe
175175

176176
try {
177177
return backingMethod.invoke(target, args);
178-
} catch (ReflectiveOperationException e) {
179-
ReflectionUtils.handleReflectionException(e);
180-
throw new UnsupportedOperationException("Should not happen", e);
178+
} catch (ReflectiveOperationException ex) {
179+
ReflectionUtils.handleReflectionException(ex);
180+
throw new UnsupportedOperationException("Should not happen", ex);
181181
}
182182
}
183183
}

src/main/java/org/springframework/data/redis/core/CloseSuppressingInvocationHandler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
5858

5959
// Invoke method on target RedisConnection.
6060
try {
61-
Object retVal = method.invoke(this.target, args);
62-
return retVal;
61+
Object returnValue = method.invoke(this.target, args);
62+
return returnValue;
6363
} catch (InvocationTargetException ex) {
6464
throw ex.getTargetException();
6565
}

src/main/java/org/springframework/data/redis/core/DefaultReactiveStreamOperations.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,11 @@ private ByteBuffer rawKey(K key) {
344344
}
345345

346346
private ByteBuffer rawHashKey(HK key) {
347+
347348
try {
348349
return serializationContext.getHashKeySerializationPair().write(key);
349-
} catch (IllegalStateException ignore) {}
350+
} catch (IllegalStateException ignore) {
351+
}
350352

351353
return ByteBuffer.wrap(objectMapper.getConversionService().convert(key, byte[].class));
352354
}
@@ -355,7 +357,8 @@ private ByteBuffer rawValue(HV value) {
355357

356358
try {
357359
return serializationContext.getHashValueSerializationPair().write(value);
358-
} catch (IllegalStateException ignore) {}
360+
} catch (IllegalStateException ignore) {
361+
}
359362

360363
return ByteBuffer.wrap(objectMapper.getConversionService().convert(value, byte[].class));
361364
}

0 commit comments

Comments
 (0)