From 5778dec7b5e3817eb416ff3f7e68ef0a4ab6d409 Mon Sep 17 00:00:00 2001 From: John Blum Date: Wed, 18 Oct 2023 18:50:40 -0700 Subject: [PATCH] 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 --- .../redis/cache/DefaultRedisCacheWriter.java | 5 +- .../data/redis/cache/RedisCache.java | 8 ++-- .../connection/AbstractRedisConnection.java | 4 +- .../data/redis/connection/RedisNode.java | 2 +- .../redis/connection/convert/Converters.java | 4 +- .../jedis/JedisClusterConnection.java | 16 +++---- .../connection/jedis/JedisConnection.java | 12 ++--- .../lettuce/LettuceClusterConnection.java | 8 ++-- .../connection/lettuce/LettuceConnection.java | 29 +++++------ .../lettuce/LettuceConnectionFactory.java | 12 ++--- .../lettuce/LettuceFutureUtils.java | 10 ++-- .../LettucePoolingConnectionProvider.java | 4 +- .../lettuce/LettuceSentinelConnection.java | 8 ++-- .../connection/lettuce/StreamConverters.java | 2 +- .../core/BoundOperationsProxyFactory.java | 6 +-- .../CloseSuppressingInvocationHandler.java | 4 +- .../core/DefaultReactiveStreamOperations.java | 7 ++- .../redis/core/DefaultValueOperations.java | 2 +- .../data/redis/core/RedisConnectionUtils.java | 4 +- .../data/redis/core/RedisTemplate.java | 6 +-- .../data/redis/core/ScanCursor.java | 6 +-- .../redis/core/convert/BinaryConverters.java | 6 +-- .../data/redis/core/convert/Bucket.java | 4 +- .../core/convert/MappingRedisConverter.java | 3 +- .../redis/core/convert/PathIndexResolver.java | 6 +-- .../core/mapping/RedisMappingContext.java | 21 ++++---- .../redis/core/script/DefaultRedisScript.java | 4 +- .../core/script/DefaultScriptExecutor.java | 7 +-- .../data/redis/core/script/DigestUtils.java | 3 +- .../redis/core/types/RedisClientInfo.java | 6 +-- .../data/redis/hash/BeanUtilsHashMapper.java | 2 +- .../data/redis/hash/Jackson2HashMapper.java | 10 ++-- .../RedisMessageListenerContainer.java | 48 ++++++++++--------- .../adapter/MessageListenerAdapter.java | 15 +++--- .../cdi/RedisKeyValueAdapterBean.java | 4 +- .../cdi/RedisKeyValueTemplateBean.java | 4 +- .../GenericJackson2JsonRedisSerializer.java | 12 ++--- .../JdkSerializationRedisSerializer.java | 4 +- .../redis/stream/DefaultStreamReceiver.java | 4 +- .../data/redis/stream/StreamPollTask.java | 20 ++++---- .../data/redis/SettingsUtils.java | 2 +- .../cache/DefaultRedisCacheWriterTests.java | 4 +- .../redis/cache/LegacyRedisCacheTests.java | 5 +- .../data/redis/cache/RedisCacheTests.java | 4 +- .../AbstractConnectionIntegrationTests.java | 23 ++++----- ...actConnectionPipelineIntegrationTests.java | 4 +- .../jedis/JedisClusterConnectionTests.java | 8 ++-- .../JedisConnectionIntegrationTests.java | 41 ++++++++-------- ...disConnectionPipelineIntegrationTests.java | 8 ++-- ...ConnectionTransactionIntegrationTests.java | 8 ++-- .../jedis/JedisConnectionUnitTests.java | 3 +- .../redis/connection/jedis/ScanTests.java | 4 +- .../JedisConnectionFactoryExtension.java | 4 +- .../LettuceConnectionFactoryTests.java | 13 ++--- .../LettuceConnectionIntegrationTests.java | 8 ++-- .../LettuceReactiveCommandsTestSupport.java | 4 +- .../LettuceSentinelIntegrationTests.java | 5 +- ...nnectionSplittingInterceptorUnitTests.java | 4 +- .../DefaultSetOperationsIntegrationTests.java | 6 ++- ...ReactiveRedisTemplateIntegrationTests.java | 26 ++++------ .../redis/core/RedisKeyValueAdapterTests.java | 3 +- .../core/RedisTemplateIntegrationTests.java | 15 ++++-- .../EnabledOnRedisAvailableCondition.java | 11 +++-- .../redis/test/condition/RedisConditions.java | 4 +- .../redis/test/condition/RedisDetector.java | 5 +- .../ParameterizedRedisTestExtension.java | 4 +- 66 files changed, 284 insertions(+), 284 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java b/src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java index 5b22ffaf4..e251b4949 100644 --- a/src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java +++ b/src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java @@ -307,8 +307,9 @@ class DefaultRedisCacheWriter implements RedisCacheWriter { // Re-interrupt current thread, to allow other participants to react. Thread.currentThread().interrupt(); - throw new PessimisticLockingFailureException(String.format("Interrupted while waiting to unlock cache %s", name), - ex); + String message = String.format("Interrupted while waiting to unlock cache %s", name); + + throw new PessimisticLockingFailureException(message, ex); } finally { statistics.incLockTime(name, System.nanoTime() - lockWaitTimeNs); } diff --git a/src/main/java/org/springframework/data/redis/cache/RedisCache.java b/src/main/java/org/springframework/data/redis/cache/RedisCache.java index 5c7193b52..db3ce3737 100644 --- a/src/main/java/org/springframework/data/redis/cache/RedisCache.java +++ b/src/main/java/org/springframework/data/redis/cache/RedisCache.java @@ -152,8 +152,8 @@ public class RedisCache extends AbstractValueAdaptingCache { try { value = valueLoader.call(); - } catch (Exception cause) { - throw new ValueRetrievalException(key, valueLoader, cause); + } catch (Exception ex) { + throw new ValueRetrievalException(key, valueLoader, ex); } put(key, value); @@ -327,14 +327,14 @@ public class RedisCache extends AbstractValueAdaptingCache { if (conversionService.canConvert(source, TypeDescriptor.valueOf(String.class))) { try { return conversionService.convert(key, String.class); - } catch (ConversionFailedException cause) { + } catch (ConversionFailedException ex) { // May fail if the given key is a collection if (isCollectionLikeOrMap(source)) { return convertCollectionLikeOrMapKey(key, source); } - throw cause; + throw ex; } } diff --git a/src/main/java/org/springframework/data/redis/connection/AbstractRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/AbstractRedisConnection.java index 71c2e0050..fcdffc4a3 100644 --- a/src/main/java/org/springframework/data/redis/connection/AbstractRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/AbstractRedisConnection.java @@ -114,8 +114,8 @@ public abstract class AbstractRedisConnection implements RedisConnection { try { connection.close(); - } catch (IOException e) { - LOGGER.info("Failed to close sentinel connection", e); + } catch (IOException ex) { + LOGGER.info("Failed to close sentinel connection", ex); } } } diff --git a/src/main/java/org/springframework/data/redis/connection/RedisNode.java b/src/main/java/org/springframework/data/redis/connection/RedisNode.java index 490e58eaa..7c66f5a1e 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisNode.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisNode.java @@ -101,7 +101,7 @@ public class RedisNode implements NamedNode { int port = -1; try { port = Integer.parseInt(portString); - } catch (RuntimeException e) { + } catch (RuntimeException ignore) { throw new IllegalArgumentException(String.format("Unparseable port number: %s", hostPortString)); } diff --git a/src/main/java/org/springframework/data/redis/connection/convert/Converters.java b/src/main/java/org/springframework/data/redis/connection/convert/Converters.java index fd6ae29d5..874e9797d 100644 --- a/src/main/java/org/springframework/data/redis/connection/convert/Converters.java +++ b/src/main/java/org/springframework/data/redis/connection/convert/Converters.java @@ -109,8 +109,8 @@ public abstract class Converters { try (StringReader stringReader = new StringReader(source)) { info.load(stringReader); - } catch (Exception cause) { - throw new RedisSystemException("Cannot read Redis info", cause); + } catch (Exception ex) { + throw new RedisSystemException("Cannot read Redis info", ex); } return info; diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java index 608034017..3d5b34d7b 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java @@ -123,8 +123,8 @@ public class JedisClusterConnection implements RedisClusterConnection { Object custerCommandExecutor = executorDfa.getPropertyValue("executor"); DirectFieldAccessor dfa = new DirectFieldAccessor(custerCommandExecutor); clusterCommandExecutor.setMaxRedirects((Integer) dfa.getPropertyValue("maxRedirects")); - } catch (Exception e) { - // ignore it and work with the executor default + } catch (Exception ignore) { + // ignore and work with the executor default } } @@ -381,8 +381,8 @@ public class JedisClusterConnection implements RedisClusterConnection { JedisMessageListener jedisPubSub = new JedisMessageListener(listener); subscription = new JedisSubscription(listener, jedisPubSub, channels, null); cluster.subscribe(jedisPubSub, channels); - } catch (Exception cause) { - throw convertJedisAccessException(cause); + } catch (Exception ex) { + throw convertJedisAccessException(ex); } } @@ -398,8 +398,8 @@ public class JedisClusterConnection implements RedisClusterConnection { JedisMessageListener jedisPubSub = new JedisMessageListener(listener); subscription = new JedisSubscription(listener, jedisPubSub, null, patterns); cluster.psubscribe(jedisPubSub, patterns); - } catch (Exception cause) { - throw convertJedisAccessException(cause); + } catch (Exception ex) { + throw convertJedisAccessException(ex); } } @@ -643,8 +643,8 @@ public class JedisClusterConnection implements RedisClusterConnection { if (!closed && disposeClusterCommandExecutorOnClose) { try { clusterCommandExecutor.destroy(); - } catch (Exception cause) { - log.warn("Cannot properly close cluster command executor", cause); + } catch (Exception ex) { + log.warn("Cannot properly close cluster command executor", ex); } } diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java index 0c23bb171..8701ec58e 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java @@ -405,17 +405,17 @@ public class JedisConnection extends AbstractRedisConnection { if (!result.isStatus()) { results.add(result.conversionRequired() ? result.convert(data) : data); } - } catch (JedisDataException e) { - DataAccessException dataAccessException = convertJedisAccessException(e); + } catch (JedisDataException ex) { + DataAccessException dataAccessException = convertJedisAccessException(ex); if (cause == null) { cause = dataAccessException; } results.add(dataAccessException); - } catch (DataAccessException e) { + } catch (DataAccessException ex) { if (cause == null) { - cause = e; + cause = ex; } - results.add(e); + results.add(ex); } } if (cause != null) { @@ -670,7 +670,7 @@ public class JedisConnection extends AbstractRedisConnection { verification = getJedis(node); verification.connect(); return verification.ping().equalsIgnoreCase("pong"); - } catch (Exception e) { + } catch (Exception ignore) { return false; } finally { if (verification != null) { diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnection.java index 8e7e2a12b..486f14a07 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnection.java @@ -380,8 +380,8 @@ public class LettuceClusterConnection extends LettuceConnection try { return getConnection().clusterCountKeysInSlot(slot); - } catch (Exception cause) { - throw this.exceptionConverter.translate(cause); + } catch (Exception ex) { + throw this.exceptionConverter.translate(ex); } } @@ -451,8 +451,8 @@ public class LettuceClusterConnection extends LettuceConnection try { return getConnection().clusterGetKeysInSlot(slot, count); - } catch (Exception cause) { - throw this.exceptionConverter.translate(cause); + } catch (Exception ex) { + throw this.exceptionConverter.translate(ex); } } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java index 9d50e0f05..5f7672e5e 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java @@ -366,8 +366,8 @@ public class LettuceConnection extends AbstractRedisConnection { try { reset(); - } catch (RuntimeException e) { - LOGGER.debug("Failed to reset connection during close", e); + } catch (RuntimeException ex) { + LOGGER.debug("Failed to reset connection during close", ex); } } @@ -468,11 +468,11 @@ public class LettuceConnection extends AbstractRedisConnection { try { results.add(result.conversionRequired() ? result.convert(result.get()) : result.get()); - } catch (DataAccessException e) { + } catch (DataAccessException ex) { if (problem == null) { - problem = e; + problem = ex; } - results.add(e); + results.add(ex); } } } @@ -488,8 +488,8 @@ public class LettuceConnection extends AbstractRedisConnection { } throw new RedisPipelineException(new QueryTimeoutException("Redis command timed out")); - } catch (Exception e) { - throw new RedisPipelineException(e); + } catch (Exception ex) { + throw new RedisPipelineException(ex); } } @@ -573,7 +573,7 @@ public class LettuceConnection extends AbstractRedisConnection { if (asyncSharedConn != null) { throw new InvalidDataAccessApiUsageException("Selecting a new database not supported due to shared connection;" - + " Use separate ConnectionFactorys to work with multiple databases"); + + " Use separate ConnectionFactory instances to work with multiple databases"); } this.dbIndex = dbIndex; @@ -930,7 +930,7 @@ public class LettuceConnection extends AbstractRedisConnection { try { connection = getConnection(node); return connection.sync().ping().equalsIgnoreCase("pong"); - } catch (Exception e) { + } catch (Exception ignore) { return false; } finally { if (connection != null) { @@ -965,8 +965,8 @@ public class LettuceConnection extends AbstractRedisConnection { try { return LettuceFutures.awaitOrCancel(cmd, timeout, TimeUnit.MILLISECONDS); - } catch (RuntimeException e) { - throw convertLettuceAccessException(e); + } catch (RuntimeException ex) { + throw convertLettuceAccessException(ex); } } @@ -1031,8 +1031,9 @@ public class LettuceConnection extends AbstractRedisConnection { if (!RedisCommand.UNKNOWN.equals(redisCommand) && redisCommand.requiresArguments()) { try { redisCommand.validateArgumentCount(args != null ? args.length : 0); - } catch (IllegalArgumentException e) { - throw new InvalidDataAccessApiUsageException(String.format("Validation failed for %s command", cmd), e); + } catch (IllegalArgumentException ex) { + String message = String.format("Validation failed for %s command", command); + throw new InvalidDataAccessApiUsageException(message, ex); } } } @@ -1041,7 +1042,7 @@ public class LettuceConnection extends AbstractRedisConnection { try { return CommandType.valueOf(name); - } catch (IllegalArgumentException e) { + } catch (IllegalArgumentException ignore) { return new CustomCommandType(name); } } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java index aebc3f51d..36ed70e85 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java @@ -1380,8 +1380,8 @@ public class LettuceConnectionFactory ((StatefulRedisClusterConnection) connection).sync().ping(); } valid = true; - } catch (Exception e) { - log.debug("Validation failed", e); + } catch (Exception ex) { + log.debug("Validation failed", ex); } } @@ -1531,8 +1531,8 @@ public class LettuceConnectionFactory try { return delegate.getConnection(connectionType); - } catch (RuntimeException e) { - throw translateException(e); + } catch (RuntimeException ex) { + throw translateException(ex); } } @@ -1541,8 +1541,8 @@ public class LettuceConnectionFactory try { return ((TargetAware) delegate).getConnection(connectionType, redisURI); - } catch (RuntimeException e) { - throw translateException(e); + } catch (RuntimeException ex) { + throw translateException(ex); } } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceFutureUtils.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceFutureUtils.java index ef4c1ceb5..6adaa5f4a 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceFutureUtils.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceFutureUtils.java @@ -66,14 +66,14 @@ class LettuceFutureUtils { try { return future.toCompletableFuture().join(); - } catch (Exception e) { + } catch (Exception ex) { - Throwable exceptionToUse = e; + Throwable exceptionToUse = ex; - if (e instanceof CompletionException) { - exceptionToUse = LettuceExceptionConverter.INSTANCE.convert((Exception) e.getCause()); + if (ex instanceof CompletionException) { + exceptionToUse = LettuceExceptionConverter.INSTANCE.convert((Exception) ex.getCause()); if (exceptionToUse == null) { - exceptionToUse = e.getCause(); + exceptionToUse = ex.getCause(); } } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettucePoolingConnectionProvider.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettucePoolingConnectionProvider.java index 41cf19ccb..c6e321b31 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettucePoolingConnectionProvider.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettucePoolingConnectionProvider.java @@ -100,8 +100,8 @@ class LettucePoolingConnectionProvider implements LettuceConnectionProvider, Red poolRef.put(connection, pool); return connectionType.cast(connection); - } catch (Exception e) { - throw new PoolException("Could not get a resource from the pool", e); + } catch (Exception ex) { + throw new PoolException("Could not get a resource from the pool", ex); } } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelConnection.java index 56e0fa357..d512e6ed7 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelConnection.java @@ -158,8 +158,8 @@ public class LettuceSentinelConnection implements RedisSentinelConnection { public List masters() { try { return LettuceConverters.toListOfRedisServer(getSentinelCommands().masters()); - } catch (Exception e) { - throw EXCEPTION_TRANSLATION.translate(e); + } catch (Exception ex) { + throw EXCEPTION_TRANSLATION.translate(ex); } } @@ -180,8 +180,8 @@ public class LettuceSentinelConnection implements RedisSentinelConnection { Assert.hasText(masterName, "Name of redis master cannot be 'null' or empty when loading replicas."); try { return LettuceConverters.toListOfRedisServer(getSentinelCommands().slaves(masterName)); - } catch (Exception e) { - throw EXCEPTION_TRANSLATION.translate(e); + } catch (Exception ex) { + throw EXCEPTION_TRANSLATION.translate(ex); } } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/StreamConverters.java b/src/main/java/org/springframework/data/redis/connection/lettuce/StreamConverters.java index a49077947..a7ff437fd 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/StreamConverters.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/StreamConverters.java @@ -140,7 +140,7 @@ class StreamConverters { try { return NumberUtils.parseNumber(tmp, Long.class); - } catch (NumberFormatException e) { + } catch (NumberFormatException ex) { return tmp; } } diff --git a/src/main/java/org/springframework/data/redis/core/BoundOperationsProxyFactory.java b/src/main/java/org/springframework/data/redis/core/BoundOperationsProxyFactory.java index fba239ab0..d4c7a5b52 100644 --- a/src/main/java/org/springframework/data/redis/core/BoundOperationsProxyFactory.java +++ b/src/main/java/org/springframework/data/redis/core/BoundOperationsProxyFactory.java @@ -175,9 +175,9 @@ class BoundOperationsProxyFactory { try { return backingMethod.invoke(target, args); - } catch (ReflectiveOperationException e) { - ReflectionUtils.handleReflectionException(e); - throw new UnsupportedOperationException("Should not happen", e); + } catch (ReflectiveOperationException ex) { + ReflectionUtils.handleReflectionException(ex); + throw new UnsupportedOperationException("Should not happen", ex); } } } diff --git a/src/main/java/org/springframework/data/redis/core/CloseSuppressingInvocationHandler.java b/src/main/java/org/springframework/data/redis/core/CloseSuppressingInvocationHandler.java index b454ded95..58dce55e8 100644 --- a/src/main/java/org/springframework/data/redis/core/CloseSuppressingInvocationHandler.java +++ b/src/main/java/org/springframework/data/redis/core/CloseSuppressingInvocationHandler.java @@ -58,8 +58,8 @@ class CloseSuppressingInvocationHandler implements InvocationHandler { // Invoke method on target RedisConnection. try { - Object retVal = method.invoke(this.target, args); - return retVal; + Object returnValue = method.invoke(this.target, args); + return returnValue; } catch (InvocationTargetException ex) { throw ex.getTargetException(); } diff --git a/src/main/java/org/springframework/data/redis/core/DefaultReactiveStreamOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultReactiveStreamOperations.java index 1244af69e..139bb2799 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultReactiveStreamOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultReactiveStreamOperations.java @@ -344,9 +344,11 @@ class DefaultReactiveStreamOperations implements ReactiveStreamOperat } private ByteBuffer rawHashKey(HK key) { + try { return serializationContext.getHashKeySerializationPair().write(key); - } catch (IllegalStateException ignore) {} + } catch (IllegalStateException ignore) { + } return ByteBuffer.wrap(objectMapper.getConversionService().convert(key, byte[].class)); } @@ -355,7 +357,8 @@ class DefaultReactiveStreamOperations implements ReactiveStreamOperat try { return serializationContext.getHashValueSerializationPair().write(value); - } catch (IllegalStateException ignore) {} + } catch (IllegalStateException ignore) { + } return ByteBuffer.wrap(objectMapper.getConversionService().convert(value, byte[].class)); } diff --git a/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java index 2bd7233b7..149543027 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java @@ -271,7 +271,7 @@ class DefaultValueOperations extends AbstractOperations implements V boolean failed = false; try { connection.pSetEx(rawKey, timeout, rawValue); - } catch (UnsupportedOperationException e) { + } catch (UnsupportedOperationException ignore) { // in case the connection does not support pSetEx return false to allow fallback to other operation. failed = true; } diff --git a/src/main/java/org/springframework/data/redis/core/RedisConnectionUtils.java b/src/main/java/org/springframework/data/redis/core/RedisConnectionUtils.java index 3f3abcac7..2956c3d88 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisConnectionUtils.java +++ b/src/main/java/org/springframework/data/redis/core/RedisConnectionUtils.java @@ -497,8 +497,8 @@ public abstract class RedisConnectionUtils { try { return method.invoke(target, args); - } catch (InvocationTargetException e) { - throw e.getCause(); + } catch (InvocationTargetException ex) { + throw ex.getCause(); } } diff --git a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java index 504219bd0..246f87687 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java @@ -685,7 +685,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return doWithKeys(connection -> { try { return connection.pExpire(rawKey, rawTimeout); - } catch (Exception e) { + } catch (Exception ignore) { // Driver may not support pExpire or we may be running on Redis 2.4 return connection.expire(rawKey, TimeoutUtils.toSeconds(timeout, unit)); } @@ -700,7 +700,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return doWithKeys(connection -> { try { return connection.pExpireAt(rawKey, date.getTime()); - } catch (Exception e) { + } catch (Exception ignore) { return connection.expireAt(rawKey, date.getTime() / 1000); } }); @@ -727,7 +727,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return doWithKeys(connection -> { try { return connection.pTtl(rawKey, timeUnit); - } catch (Exception e) { + } catch (Exception ignore) { // Driver may not support pTtl or we may be running on Redis 2.4 return connection.ttl(rawKey, timeUnit); } diff --git a/src/main/java/org/springframework/data/redis/core/ScanCursor.java b/src/main/java/org/springframework/data/redis/core/ScanCursor.java index d40d990f4..1b5729dcf 100644 --- a/src/main/java/org/springframework/data/redis/core/ScanCursor.java +++ b/src/main/java/org/springframework/data/redis/core/ScanCursor.java @@ -88,13 +88,13 @@ public abstract class ScanCursor implements Cursor { try { processScanResult(doScan(cursorId, this.scanOptions)); - } catch (RuntimeException e) { + } catch (RuntimeException ex) { try { close(); } catch (RuntimeException nested) { - e.addSuppressed(nested); + ex.addSuppressed(nested); } - throw e; + throw ex; } } diff --git a/src/main/java/org/springframework/data/redis/core/convert/BinaryConverters.java b/src/main/java/org/springframework/data/redis/core/convert/BinaryConverters.java index b4ab86e94..f15e0966b 100644 --- a/src/main/java/org/springframework/data/redis/core/convert/BinaryConverters.java +++ b/src/main/java/org/springframework/data/redis/core/convert/BinaryConverters.java @@ -281,14 +281,12 @@ final class BinaryConverters { String value = toString(source); try { return new Date(NumberUtils.parseNumber(value, Long.class)); - } catch (NumberFormatException nfe) { - // ignore + } catch (NumberFormatException ignore) { } try { return DateFormat.getInstance().parse(value); - } catch (ParseException e) { - // ignore + } catch (ParseException ignore) { } throw new IllegalArgumentException(String.format("Cannot parse date out of %s", Arrays.toString(source))); diff --git a/src/main/java/org/springframework/data/redis/core/convert/Bucket.java b/src/main/java/org/springframework/data/redis/core/convert/Bucket.java index dd84cbed0..ac2d523c3 100644 --- a/src/main/java/org/springframework/data/redis/core/convert/Bucket.java +++ b/src/main/java/org/springframework/data/redis/core/convert/Bucket.java @@ -306,9 +306,9 @@ public class Bucket { try { return new String(raw, CHARSET); - } catch (Exception e) { - // Ignore this one + } catch (Exception ignore) { } + return null; } diff --git a/src/main/java/org/springframework/data/redis/core/convert/MappingRedisConverter.java b/src/main/java/org/springframework/data/redis/core/convert/MappingRedisConverter.java index 1ba24db98..d53db84f7 100644 --- a/src/main/java/org/springframework/data/redis/core/convert/MappingRedisConverter.java +++ b/src/main/java/org/springframework/data/redis/core/convert/MappingRedisConverter.java @@ -571,8 +571,7 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean { PersistentPropertyPath persistentPropertyPath = mappingContext .getPersistentPropertyPath(path, type); return persistentPropertyPath.getLeafProperty(); - } catch (Exception e) { - // that's just fine + } catch (Exception ignore) { } return null; diff --git a/src/main/java/org/springframework/data/redis/core/convert/PathIndexResolver.java b/src/main/java/org/springframework/data/redis/core/convert/PathIndexResolver.java index 835c6a02a..bcfacf2c8 100644 --- a/src/main/java/org/springframework/data/redis/core/convert/PathIndexResolver.java +++ b/src/main/java/org/springframework/data/redis/core/convert/PathIndexResolver.java @@ -177,9 +177,9 @@ public class PathIndexResolver implements IndexResolver { if (typeHint.equals(TypeInformation.OBJECT) || typeHint.getClass().isInterface()) { try { typeHint = mappingContext.getRequiredPersistentEntity(propertyValue.getClass()).getTypeInformation(); - } catch (Exception e) { - // ignore for cases where property value cannot be resolved as an entity, in that case the provided type - // hint has to be sufficient + } catch (Exception ignore) { + // ignore for cases where property value cannot be resolved as an entity, in that case + // the provided type hint has to be sufficient } } return typeHint; diff --git a/src/main/java/org/springframework/data/redis/core/mapping/RedisMappingContext.java b/src/main/java/org/springframework/data/redis/core/mapping/RedisMappingContext.java index b4145e38f..653d2533f 100644 --- a/src/main/java/org/springframework/data/redis/core/mapping/RedisMappingContext.java +++ b/src/main/java/org/springframework/data/redis/core/mapping/RedisMappingContext.java @@ -240,15 +240,18 @@ public class RedisMappingContext extends KeyValueMappingContext implements RedisScript, InitializingBean { try { return scriptSource.getScriptAsString(); - } catch (IOException e) { - throw new ScriptingException("Error reading script text", e); + } catch (IOException ex) { + throw new ScriptingException("Error reading script text", ex); } } diff --git a/src/main/java/org/springframework/data/redis/core/script/DefaultScriptExecutor.java b/src/main/java/org/springframework/data/redis/core/script/DefaultScriptExecutor.java index 5dc6c8433..23032af69 100644 --- a/src/main/java/org/springframework/data/redis/core/script/DefaultScriptExecutor.java +++ b/src/main/java/org/springframework/data/redis/core/script/DefaultScriptExecutor.java @@ -75,10 +75,11 @@ public class DefaultScriptExecutor implements ScriptExecutor { Object result; try { result = connection.evalSha(script.getSha1(), returnType, numKeys, keysAndArgs); - } catch (Exception e) { + } catch (Exception ex) { - if (!ScriptUtils.exceptionContainsNoScriptError(e)) { - throw e instanceof RuntimeException ? (RuntimeException) e : new RedisSystemException(e.getMessage(), e); + if (!ScriptUtils.exceptionContainsNoScriptError(ex)) { + throw ex instanceof RuntimeException runtimeException ? runtimeException + : new RedisSystemException(ex.getMessage(), ex); } result = connection.eval(scriptBytes(script), returnType, numKeys, keysAndArgs); diff --git a/src/main/java/org/springframework/data/redis/core/script/DigestUtils.java b/src/main/java/org/springframework/data/redis/core/script/DigestUtils.java index 3d8f379e9..60746f402 100644 --- a/src/main/java/org/springframework/data/redis/core/script/DigestUtils.java +++ b/src/main/java/org/springframework/data/redis/core/script/DigestUtils.java @@ -60,7 +60,8 @@ abstract public class DigestUtils { try { return MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException ex) { - throw new IllegalStateException("Could not find MessageDigest with algorithm \"" + algorithm + "\"", ex); + String message = String.format("Could not find MessageDigest with algorithm \"%s\"", algorithm); + throw new IllegalStateException(message, ex); } } } diff --git a/src/main/java/org/springframework/data/redis/core/types/RedisClientInfo.java b/src/main/java/org/springframework/data/redis/core/types/RedisClientInfo.java index ffa38fe03..04b103a9d 100644 --- a/src/main/java/org/springframework/data/redis/core/types/RedisClientInfo.java +++ b/src/main/java/org/springframework/data/redis/core/types/RedisClientInfo.java @@ -273,9 +273,9 @@ public class RedisClientInfo { Properties properties = new Properties(); try { properties.load(new StringReader(source.replace(' ', '\n'))); - } catch (IOException e) { - throw new IllegalArgumentException(String.format("Properties could not be loaded from String '%s'", source), - e); + } catch (IOException ex) { + String message = String.format("Properties could not be loaded from String '%s'", source); + throw new IllegalArgumentException(message, ex); } return new RedisClientInfo(properties); } diff --git a/src/main/java/org/springframework/data/redis/hash/BeanUtilsHashMapper.java b/src/main/java/org/springframework/data/redis/hash/BeanUtilsHashMapper.java index 669fbe4ce..267cd9891 100644 --- a/src/main/java/org/springframework/data/redis/hash/BeanUtilsHashMapper.java +++ b/src/main/java/org/springframework/data/redis/hash/BeanUtilsHashMapper.java @@ -71,7 +71,7 @@ public class BeanUtilsHashMapper implements HashMapper { return result; } catch (Exception ex) { - throw new IllegalArgumentException("Cannot describe object " + object, ex); + throw new IllegalArgumentException(String.format("Cannot describe object %s", object), ex); } } } diff --git a/src/main/java/org/springframework/data/redis/hash/Jackson2HashMapper.java b/src/main/java/org/springframework/data/redis/hash/Jackson2HashMapper.java index 6786e3c1a..245d507b1 100644 --- a/src/main/java/org/springframework/data/redis/hash/Jackson2HashMapper.java +++ b/src/main/java/org/springframework/data/redis/hash/Jackson2HashMapper.java @@ -264,8 +264,8 @@ public class Jackson2HashMapper implements HashMapper { return this.typingMapper.treeToValue(this.untypedMapper.valueToTree(hash), Object.class); - } catch (IOException cause) { - throw new MappingException(cause.getMessage(), cause); + } catch (IOException ex) { + throw new MappingException(ex.getMessage(), ex); } } @@ -424,9 +424,9 @@ public class Jackson2HashMapper implements HashMapper { try { resultMap.put(propertyPrefix, next.binaryValue()); } - catch (IOException cause) { + catch (IOException ex) { String message = String.format("Cannot read binary value of '%s'", propertyPrefix); - throw new IllegalStateException(message, cause); + throw new IllegalStateException(message, ex); } break; @@ -526,7 +526,7 @@ public class Jackson2HashMapper implements HashMapper { try { return ctxt.getConfig().getDateFormat().parse(value.toString()); - } catch (ParseException cause) { + } catch (ParseException ignore) { return new Date(NumberUtils.parseNumber(value.toString(), Long.class)); } } diff --git a/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java b/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java index ea9b8deb9..2a0036ba9 100644 --- a/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java +++ b/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java @@ -375,17 +375,17 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab try { futureToAwait.get(getMaxSubscriptionRegistrationWaitingTime(), TimeUnit.MILLISECONDS); - } catch (InterruptedException cause) { + } catch (InterruptedException ex) { Thread.currentThread().interrupt(); - } catch (ExecutionException cause) { + } catch (ExecutionException ex) { - if (cause.getCause() instanceof DataAccessException) { - throw new RedisListenerExecutionFailedException(cause.getMessage(), cause.getCause()); + if (ex.getCause() instanceof DataAccessException) { + throw new RedisListenerExecutionFailedException(ex.getMessage(), ex.getCause()); } - throw new CompletionException(cause.getCause()); - } catch (TimeoutException cause) { - throw new IllegalStateException("Subscription registration timeout exceeded", cause); + throw new CompletionException(ex.getCause()); + } catch (TimeoutException ex) { + throw new IllegalStateException("Subscription registration timeout exceeded", ex); } } @@ -535,9 +535,10 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab try { future.get(getMaxSubscriptionRegistrationWaitingTime(), TimeUnit.MILLISECONDS); - } catch (InterruptedException cause) { + } catch (InterruptedException ex) { Thread.currentThread().interrupt(); - } catch (ExecutionException | TimeoutException ignore) {} + } catch (ExecutionException | TimeoutException ignore) { + } } @Override @@ -696,13 +697,13 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab try { future.join(); - } catch (CompletionException cause) { + } catch (CompletionException ex) { - if (cause.getCause() instanceof DataAccessException) { - throw new RedisListenerExecutionFailedException(cause.getMessage(), cause.getCause()); + if (ex.getCause() instanceof DataAccessException) { + throw new RedisListenerExecutionFailedException(ex.getMessage(), ex.getCause()); } - throw cause; + throw ex; } } } @@ -935,8 +936,9 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } return true; - } catch (InterruptedException interEx) { - logger.debug("Thread interrupted while sleeping the recovery interval"); + + } catch (InterruptedException ex) { + logDebug(() -> "Thread interrupted while sleeping the recovery interval"); Thread.currentThread().interrupt(); return false; } @@ -1195,8 +1197,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } catch (Throwable t) { handleSubscriptionException(initFuture, backOffExecution, t); } - } catch (RuntimeException e) { - initFuture.completeExceptionally(e); + } catch (RuntimeException ex) { + initFuture.completeExceptionally(ex); } return initFuture; @@ -1298,8 +1300,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab try { sub.close(); - } catch (Exception e) { - logger.warn("Unable to unsubscribe from subscriptions", e); + } catch (Exception ex) { + logger.warn("Unable to unsubscribe from subscriptions", ex); } } } @@ -1318,8 +1320,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab logger.trace("Closing connection"); try { connection.close(); - } catch (Exception e) { - logger.warn("Error closing subscription connection", e); + } catch (Exception ex) { + logger.warn("Error closing subscription connection", ex); } } } @@ -1415,8 +1417,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab new SynchronizingMessageListener.SubscriptionSynchronization(patterns, Collections.emptySet(), () -> { try { subscribeChannel(channels.toArray(new byte[0][])); - } catch (Exception cause) { - handleSubscriptionException(subscriptionDone, backOffExecution, cause); + } catch (Exception ex) { + handleSubscriptionException(subscriptionDone, backOffExecution, ex); } })); } else { diff --git a/src/main/java/org/springframework/data/redis/listener/adapter/MessageListenerAdapter.java b/src/main/java/org/springframework/data/redis/listener/adapter/MessageListenerAdapter.java index 321fb6aad..f652faafd 100644 --- a/src/main/java/org/springframework/data/redis/listener/adapter/MessageListenerAdapter.java +++ b/src/main/java/org/springframework/data/redis/listener/adapter/MessageListenerAdapter.java @@ -369,16 +369,19 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener try { invoker.invoke(arguments); } catch (InvocationTargetException ex) { + Throwable targetEx = ex.getTargetException(); - if (targetEx instanceof DataAccessException) { - throw (DataAccessException) targetEx; + + if (targetEx instanceof DataAccessException dataAccessException) { + throw dataAccessException; } else { - throw new RedisListenerExecutionFailedException("Listener method '" + methodName + "' threw exception", - targetEx); + String message = String.format("Listener method '%s' threw exception", methodName); + throw new RedisListenerExecutionFailedException(message, targetEx); } } catch (Throwable ex) { - throw new RedisListenerExecutionFailedException("Failed to invoke target method '" + methodName - + "' with arguments " + ObjectUtils.nullSafeToString(arguments), ex); + String message = String.format("Failed to invoke target method '%s' with arguments %s", methodName, + ObjectUtils.nullSafeToString(arguments)); + throw new RedisListenerExecutionFailedException(message, ex); } } diff --git a/src/main/java/org/springframework/data/redis/repository/cdi/RedisKeyValueAdapterBean.java b/src/main/java/org/springframework/data/redis/repository/cdi/RedisKeyValueAdapterBean.java index e92315af2..0cab13f6c 100644 --- a/src/main/java/org/springframework/data/redis/repository/cdi/RedisKeyValueAdapterBean.java +++ b/src/main/java/org/springframework/data/redis/repository/cdi/RedisKeyValueAdapterBean.java @@ -87,8 +87,8 @@ public class RedisKeyValueAdapterBean extends CdiBean { if (instance instanceof DisposableBean) { try { instance.destroy(); - } catch (Exception e) { - throw new IllegalStateException(e); + } catch (Exception ex) { + throw new IllegalStateException(ex); } } diff --git a/src/main/java/org/springframework/data/redis/repository/cdi/RedisKeyValueTemplateBean.java b/src/main/java/org/springframework/data/redis/repository/cdi/RedisKeyValueTemplateBean.java index 39119292d..e0a3e1023 100644 --- a/src/main/java/org/springframework/data/redis/repository/cdi/RedisKeyValueTemplateBean.java +++ b/src/main/java/org/springframework/data/redis/repository/cdi/RedisKeyValueTemplateBean.java @@ -73,8 +73,8 @@ public class RedisKeyValueTemplateBean extends CdiBean { try { ((DisposableBean) instance.getMappingContext()).destroy(); instance.destroy(); - } catch (Exception e) { - throw new IllegalStateException(e); + } catch (Exception ex) { + throw new IllegalStateException(ex); } } diff --git a/src/main/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializer.java b/src/main/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializer.java index bc7cc4d70..ec3903e67 100644 --- a/src/main/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializer.java @@ -218,9 +218,9 @@ public class GenericJackson2JsonRedisSerializer implements RedisSerializer try { return serializer.convert(value); - } catch (Exception cause) { - throw new SerializationException("Cannot serialize", cause); + } catch (Exception ex) { + throw new SerializationException("Cannot serialize", ex); } } diff --git a/src/main/java/org/springframework/data/redis/stream/DefaultStreamReceiver.java b/src/main/java/org/springframework/data/redis/stream/DefaultStreamReceiver.java index d5e61abb3..19b3a10d3 100644 --- a/src/main/java/org/springframework/data/redis/stream/DefaultStreamReceiver.java +++ b/src/main/java/org/springframework/data/redis/stream/DefaultStreamReceiver.java @@ -326,8 +326,8 @@ class DefaultStreamReceiver> implements StreamReceiver try { return deserializer.apply(it); - } catch (RuntimeException e) { - throw new ConversionFailedException(TypeDescriptor.forObject(it), targetType, it, e); + } catch (RuntimeException ex) { + throw new ConversionFailedException(TypeDescriptor.forObject(it), targetType, it, ex); } }).onErrorResume(throwable -> Flux.from(resumeFunction.apply(throwable)).then().map(it -> (V) new Object())) // .subscribe(getSubscriber()); diff --git a/src/main/java/org/springframework/data/redis/stream/StreamPollTask.java b/src/main/java/org/springframework/data/redis/stream/StreamPollTask.java index 39d5252c7..2241246a2 100644 --- a/src/main/java/org/springframework/data/redis/stream/StreamPollTask.java +++ b/src/main/java/org/springframework/data/redis/stream/StreamPollTask.java @@ -127,17 +127,17 @@ class StreamPollTask> implements Task { List raw = readRecords(); deserializeAndEmitRecords(raw); - } catch (InterruptedException e) { + } catch (InterruptedException ex) { cancel(); Thread.currentThread().interrupt(); - } catch (RuntimeException e) { + } catch (RuntimeException ex) { - if (cancelSubscriptionOnError.test(e)) { + if (cancelSubscriptionOnError.test(ex)) { cancel(); } - errorHandler.handleError(e); + errorHandler.handleError(ex); } } while (pollState.isSubscriptionActive()); } @@ -155,17 +155,17 @@ class StreamPollTask> implements Task { pollState.updateReadOffset(raw.getId().getValue()); V record = convertRecord(raw); listener.onMessage(record); - } catch (RuntimeException e) { + } catch (RuntimeException ex) { - if (cancelSubscriptionOnError.test(e)) { + if (cancelSubscriptionOnError.test(ex)) { cancel(); - errorHandler.handleError(e); + errorHandler.handleError(ex); return; } - errorHandler.handleError(e); + errorHandler.handleError(ex); } } } @@ -174,8 +174,8 @@ class StreamPollTask> implements Task { try { return deserializer.apply(record); - } catch (RuntimeException e) { - throw new ConversionFailedException(TypeDescriptor.forObject(record), targetType, record, e); + } catch (RuntimeException ex) { + throw new ConversionFailedException(TypeDescriptor.forObject(record), targetType, record, ex); } } diff --git a/src/test/java/org/springframework/data/redis/SettingsUtils.java b/src/test/java/org/springframework/data/redis/SettingsUtils.java index c317b4503..51ea95a48 100644 --- a/src/test/java/org/springframework/data/redis/SettingsUtils.java +++ b/src/test/java/org/springframework/data/redis/SettingsUtils.java @@ -49,7 +49,7 @@ public abstract class SettingsUtils { try { SETTINGS.load(SettingsUtils.class.getResourceAsStream("/org/springframework/data/redis/test.properties")); - } catch (Exception e) { + } catch (Exception ignore) { throw new IllegalArgumentException("Cannot read settings"); } } diff --git a/src/test/java/org/springframework/data/redis/cache/DefaultRedisCacheWriterTests.java b/src/test/java/org/springframework/data/redis/cache/DefaultRedisCacheWriterTests.java index fdf7f0002..42392b52c 100644 --- a/src/test/java/org/springframework/data/redis/cache/DefaultRedisCacheWriterTests.java +++ b/src/test/java/org/springframework/data/redis/cache/DefaultRedisCacheWriterTests.java @@ -318,8 +318,8 @@ public class DefaultRedisCacheWriterTests { try { writer.put(CACHE_NAME, binaryCacheKey, binaryCacheValue, Duration.ZERO); - } catch (Exception e) { - exceptionRef.set(e); + } catch (Exception ex) { + exceptionRef.set(ex); } finally { afterWrite.countDown(); } diff --git a/src/test/java/org/springframework/data/redis/cache/LegacyRedisCacheTests.java b/src/test/java/org/springframework/data/redis/cache/LegacyRedisCacheTests.java index cd597c61a..cc616999f 100644 --- a/src/test/java/org/springframework/data/redis/cache/LegacyRedisCacheTests.java +++ b/src/test/java/org/springframework/data/redis/cache/LegacyRedisCacheTests.java @@ -207,7 +207,7 @@ public class LegacyRedisCacheTests { Runnable putCache = () -> { try { cache.put(key1, value1); - } catch (IllegalMonitorStateException e) { + } catch (IllegalMonitorStateException ex) { monitorStateException.set(true); } finally { latch.countDown(); @@ -304,8 +304,7 @@ public class LegacyRedisCacheTests { try { cache.put(key, null); - } catch (IllegalArgumentException e) { - // forget this one. + } catch (IllegalArgumentException expected) { } assertThat(cache.get(key).get()).isEqualTo(value); diff --git a/src/test/java/org/springframework/data/redis/cache/RedisCacheTests.java b/src/test/java/org/springframework/data/redis/cache/RedisCacheTests.java index abc4c1c20..1463756a3 100644 --- a/src/test/java/org/springframework/data/redis/cache/RedisCacheTests.java +++ b/src/test/java/org/springframework/data/redis/cache/RedisCacheTests.java @@ -469,8 +469,8 @@ public class RedisCacheTests { prepare.countDown(); try { prepareForReturn.await(1, TimeUnit.MINUTES); - } catch (InterruptedException e) { - throw new RuntimeException(e); + } catch (InterruptedException ex) { + throw new RuntimeException(ex); } return storage.get(); diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java index b6b12293e..f5b0d4bf4 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java @@ -158,9 +158,8 @@ public abstract class AbstractConnectionIntegrationTests { // since we use more than one db we're required to flush them all connection.flushAll(); - } catch (Exception e) { - // Connection may be closed in certain cases, like after pub/sub - // tests + } catch (Exception ignore) { + // Connection may be closed in certain cases, like after pub/sub tests } connection.close(); connection = null; @@ -584,8 +583,7 @@ public abstract class AbstractConnectionIntegrationTests { try { connection.decr((String) null); fail("Decrement should fail with null key"); - } catch (Exception ex) { - // expected + } catch (Exception expected) { } } @@ -598,8 +596,7 @@ public abstract class AbstractConnectionIntegrationTests { try { connection.append(key, null); fail("Append should fail with null value"); - } catch (DataAccessException ex) { - // expected + } catch (DataAccessException expected) { } } @@ -611,8 +608,7 @@ public abstract class AbstractConnectionIntegrationTests { try { connection.hExists(key, null); fail("hExists should fail with null key"); - } catch (DataAccessException ex) { - // expected + } catch (DataAccessException expected) { } } @@ -626,8 +622,7 @@ public abstract class AbstractConnectionIntegrationTests { try { connection.hSet(key, field, null); fail("hSet should fail with null value"); - } catch (DataAccessException ex) { - // expected + } catch (DataAccessException expected) { } } @@ -665,7 +660,8 @@ public abstract class AbstractConnectionIntegrationTests { try { Thread.sleep(500); - } catch (InterruptedException o_O) {} + } catch (InterruptedException ignore) { + } // open a new connection RedisConnection connection2 = connectionFactory.getConnection(); @@ -708,7 +704,8 @@ public abstract class AbstractConnectionIntegrationTests { try { Thread.sleep(500); - } catch (InterruptedException o_O) {} + } catch (InterruptedException ignore) { + } // open a new connection RedisConnection connection2 = connectionFactory.getConnection(); diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionPipelineIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionPipelineIntegrationTests.java index 460f15452..3b4927fea 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionPipelineIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionPipelineIntegrationTests.java @@ -182,8 +182,8 @@ abstract public class AbstractConnectionPipelineIntegrationTests extends Abstrac try { // we give redis some time to keep up Thread.sleep(10); - } catch (InterruptedException e) { - e.printStackTrace(); + } catch (InterruptedException ex) { + ex.printStackTrace(); } return connection.closePipeline(); diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java index 78ffeb756..805292a22 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java @@ -123,8 +123,8 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { for (ConnectionPool pool : nativeConnection.getClusterNodes().values()) { try (Jedis jedis = new Jedis(pool.getResource())) { jedis.flushAll(); - } catch (Exception e) { - // ignore this one since we cannot remove data from replicas + } catch (Exception ignore) { + // ignore since we cannot remove data from replicas } } } @@ -2857,8 +2857,8 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { try { clusterConnection.scriptingCommands().evalSha(luaScriptBin, ReturnType.VALUE, 1, keyAndArgs); fail("expected InvalidDataAccessApiUsageException"); - } catch (InvalidDataAccessApiUsageException e) { - assertThat(e.getMessage()).contains("NOSCRIPT"); + } catch (InvalidDataAccessApiUsageException ex) { + assertThat(ex.getMessage()).contains("NOSCRIPT"); } } diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java index 24601dfa8..ca738aa93 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java @@ -68,17 +68,14 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati public void tearDown() { try { connection.flushAll(); - } catch (Exception e) { - // Jedis leaves some incomplete data in OutputStream on NPE caused - // by null key/value tests - // Attempting to flush the DB or close the connection will result in - // error on sending QUIT to Redis + } catch (Exception ignore) { + // Jedis leaves some incomplete data in OutputStream on NPE caused by null key/value tests + // Attempting to flush the DB or close the connection will result in error on sending QUIT to Redis } try { connection.close(); - } catch (Exception e) { - // silently close connection + } catch (Exception ignore) { } connection = null; @@ -224,16 +221,16 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati RedisConnection con = connectionFactory.getConnection(); try { Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); + } catch (InterruptedException ex) { + ex.printStackTrace(); } con.publish(expectedChannel.getBytes(), expectedMessage.getBytes()); try { Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); + } catch (InterruptedException ex) { + ex.printStackTrace(); } /* @@ -282,8 +279,8 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati RedisConnection con = connectionFactory.getConnection(); try { Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); + } catch (InterruptedException ex) { + ex.printStackTrace(); } con.publish("channel1".getBytes(), expectedMessage.getBytes()); @@ -291,8 +288,8 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati try { Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); + } catch (InterruptedException ex) { + ex.printStackTrace(); } con.close(); @@ -331,14 +328,14 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati factory2.setPort(SettingsUtils.getPort()); factory2.afterPropertiesSet(); - RedisConnection conn = factory2.getConnection(); - try { + try (RedisConnection conn = factory2.getConnection()) { conn.get(null); - } catch (Exception e) {} - conn.close(); - // Make sure we don't end up with broken connection - factory2.getConnection().dbSize(); - factory2.destroy(); + } catch (Exception ignore) { + } finally { + // Make sure we don't end up with broken connection + factory2.getConnection().dbSize(); + factory2.destroy(); + } } @Test // GH-2356 diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineIntegrationTests.java index 74f3139bd..921b74381 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineIntegrationTests.java @@ -48,11 +48,9 @@ public class JedisConnectionPipelineIntegrationTests extends AbstractConnectionP try { connection.flushAll(); connection.close(); - } catch (Exception e) { - // Jedis leaves some incomplete data in OutputStream on NPE caused - // by null key/value tests - // Attempting to close the connection will result in error on - // sending QUIT to Redis + } catch (Exception ignore) { + // Jedis leaves some incomplete data in OutputStream on NPE caused by null key/value tests + // Attempting to close the connection will result in error on sending QUIT to Redis } connection = null; } diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionTransactionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionTransactionIntegrationTests.java index 6963ec38e..4e287e1c9 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionTransactionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionTransactionIntegrationTests.java @@ -46,11 +46,9 @@ public class JedisConnectionTransactionIntegrationTests extends AbstractConnecti try { connection.flushAll(); connection.close(); - } catch (Exception e) { - // Jedis leaves some incomplete data in OutputStream on NPE caused - // by null key/value tests - // Attempting to close the connection will result in error on - // sending QUIT to Redis + } catch (Exception ignore) { + // Jedis leaves some incomplete data in OutputStream on NPE caused by null key/value tests + // Attempting to close the connection will result in error on sending QUIT to Redis } connection = null; } diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionUnitTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionUnitTests.java index 2a3927447..ea53373e2 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionUnitTests.java @@ -65,8 +65,7 @@ class JedisConnectionUnitTests { try { connection.shutdown(null); - } catch (InvalidDataAccessApiUsageException e) { - // all good. Sometimes it throws an Exception. + } catch (InvalidDataAccessApiUsageException ignore) { } verify(jedisSpy).shutdown(); diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/ScanTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/ScanTests.java index ba1cef1e2..e13715b87 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/ScanTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/ScanTests.java @@ -100,8 +100,8 @@ public class ScanTests { cursorMap.next(); } cursorMap.close(); - } catch (Exception e) { - exception.set(e); + } catch (Exception ex) { + exception.set(ex); } }); } diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/extension/JedisConnectionFactoryExtension.java b/src/test/java/org/springframework/data/redis/connection/jedis/extension/JedisConnectionFactoryExtension.java index bba8ce1fb..a32786105 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/extension/JedisConnectionFactoryExtension.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/extension/JedisConnectionFactoryExtension.java @@ -224,8 +224,8 @@ public class JedisConnectionFactoryExtension implements ParameterResolver { try { mayClose = true; destroy(); - } catch (Exception e) { - e.printStackTrace(); + } catch (Exception ex) { + ex.printStackTrace(); } } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java index 1be106f79..84d106088 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java @@ -97,7 +97,7 @@ class LettuceConnectionFactoryTests { try { connection.get("test3"); fail("Expected exception using natively closed conn"); - } catch (RedisSystemException e) { + } catch (RedisSystemException expected) { // expected, shared conn is closed } DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory.getConnection()); @@ -118,7 +118,7 @@ class LettuceConnectionFactoryTests { try { conn2.set("anotherkey", "anothervalue"); fail("Expected exception using natively closed conn"); - } catch (RedisSystemException e) { + } catch (RedisSystemException expected) { // expected, as we are re-using the natively closed conn } finally { conn2.close(); @@ -270,7 +270,8 @@ class LettuceConnectionFactoryTests { try { factory.getConnection(); fail("Expected connection failure exception"); - } catch (RedisConnectionFailureException e) {} + } catch (RedisConnectionFailureException expected) { + } } @Test @@ -463,9 +464,9 @@ class LettuceConnectionFactoryTests { try { connection.ping(); fail("Expected RedisException: Master is currently unknown"); - } catch (RedisSystemException e) { - assertThat(e.getCause()).isInstanceOf(RedisException.class); - assertThat(e.getCause().getMessage()).contains("Master is currently unknown"); + } catch (RedisSystemException ex) { + assertThat(ex.getCause()).isInstanceOf(RedisException.class); + assertThat(ex.getCause().getMessage()).contains("Master is currently unknown"); } finally { connection.close(); } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java index b18e5283e..342e61d2e 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java @@ -97,7 +97,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra try { connection.exec(); fail("Expected exception resuming tx"); - } catch (RedisSystemException e) { + } catch (RedisSystemException expected) { // expected, can't resume tx after closing conn } } @@ -115,7 +115,8 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra // can't do blocking ops after closing connection.bLPop(1, "what".getBytes()); fail("Expected exception using a closed conn for dedicated ops"); - } catch (RedisSystemException e) {} + } catch (RedisSystemException expected) { + } } @Test @@ -133,7 +134,8 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra try { connection.set("foo".getBytes(), "bar".getBytes()); fail("Exception should be thrown trying to use a closed connection"); - } catch (RedisSystemException e) {} + } catch (RedisSystemException expected) { + } factory2.destroy(); } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveCommandsTestSupport.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveCommandsTestSupport.java index 1ba37c1c4..fee8db144 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveCommandsTestSupport.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveCommandsTestSupport.java @@ -166,8 +166,8 @@ public abstract class LettuceReactiveCommandsTestSupport { if (nativeBinaryConnectionProvider instanceof DisposableBean) { ((DisposableBean) nativeBinaryConnectionProvider).destroy(); } - } catch (Exception e) { - throw new RuntimeException(e); + } catch (Exception ex) { + throw new RuntimeException(ex); } } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelIntegrationTests.java index 539138169..4a8cbe243 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelIntegrationTests.java @@ -78,9 +78,8 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati // since we use more than one db we're required to flush them all connection.flushAll(); - } catch (Exception e) { - // Connection may be closed in certain cases, like after pub/sub - // tests + } catch (Exception ignore) { + // Connection may be closed in certain cases, like after pub/sub tests } connection.close(); } diff --git a/src/test/java/org/springframework/data/redis/core/ConnectionSplittingInterceptorUnitTests.java b/src/test/java/org/springframework/data/redis/core/ConnectionSplittingInterceptorUnitTests.java index d023caa96..e6499c8e2 100644 --- a/src/test/java/org/springframework/data/redis/core/ConnectionSplittingInterceptorUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/ConnectionSplittingInterceptorUnitTests.java @@ -55,8 +55,8 @@ class ConnectionSplittingInterceptorUnitTests { try { WRITE_METHOD = ClassUtils.getMethod(RedisConnection.class, "expire", byte[].class, long.class); READONLY_METHOD = ClassUtils.getMethod(RedisConnection.class, "keys", byte[].class); - } catch (Exception e) { - throw new RuntimeException(e); + } catch (Exception ex) { + throw new RuntimeException(ex); } } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsIntegrationTests.java index 6c09a7208..ce8773388 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsIntegrationTests.java @@ -103,7 +103,8 @@ public class DefaultSetOperationsIntegrationTests { try { setOps.randomMembers(keyFactory.instance(), -1); fail("IllegalArgumentException should be thrown"); - } catch (IllegalArgumentException e) {} + } catch (IllegalArgumentException expected) { + } } @ParameterizedRedisTest @@ -112,7 +113,8 @@ public class DefaultSetOperationsIntegrationTests { try { setOps.distinctRandomMembers(keyFactory.instance(), -2); fail("IllegalArgumentException should be thrown"); - } catch (IllegalArgumentException e) {} + } catch (IllegalArgumentException expected) { + } } @SuppressWarnings("unchecked") diff --git a/src/test/java/org/springframework/data/redis/core/ReactiveRedisTemplateIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/ReactiveRedisTemplateIntegrationTests.java index f6d5bdcf1..f610d28b1 100644 --- a/src/test/java/org/springframework/data/redis/core/ReactiveRedisTemplateIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/ReactiveRedisTemplateIntegrationTests.java @@ -97,14 +97,10 @@ public class ReactiveRedisTemplateIntegrationTests { @EnabledOnCommand("COPY") void copy() { - ReactiveRedisClusterConnection connection = null; - try { - connection = redisTemplate.getConnectionFactory().getReactiveClusterConnection(); - assumeThat(connection == null).isTrue(); - } catch (InvalidDataAccessApiUsageException e) {} finally { - if (connection != null) { - connection.close(); - } + try (ReactiveRedisClusterConnection connection = redisTemplate.getConnectionFactory() + .getReactiveClusterConnection()){ + assumeThat(connection).isNull(); + } catch (InvalidDataAccessApiUsageException ignore) { } K key = keyFactory.instance(); @@ -399,23 +395,17 @@ public class ReactiveRedisTemplateIntegrationTests { @ParameterizedRedisTest // DATAREDIS-602 void move() { - ReactiveRedisClusterConnection connection = null; - try { - connection = redisTemplate.getConnectionFactory().getReactiveClusterConnection(); - assumeThat(connection == null).isTrue(); - } catch (InvalidDataAccessApiUsageException e) {} finally { - if (connection != null) { - connection.close(); - } + try (ReactiveRedisClusterConnection connection = redisTemplate.getConnectionFactory() + .getReactiveClusterConnection()) { + assumeThat(connection).isNull(); + } catch (InvalidDataAccessApiUsageException ignore) { } K key = keyFactory.instance(); V value = valueFactory.instance(); redisTemplate.opsForValue().set(key, value).as(StepVerifier::create).expectNext(true).verifyComplete(); - redisTemplate.move(key, 5).as(StepVerifier::create).expectNext(true).verifyComplete(); - redisTemplate.hasKey(key).as(StepVerifier::create).expectNext(false).verifyComplete(); } diff --git a/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterTests.java b/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterTests.java index e20be742f..d9ac4c732 100644 --- a/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterTests.java +++ b/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterTests.java @@ -102,8 +102,7 @@ public class RedisKeyValueAdapterTests { try { adapter.destroy(); - } catch (Exception e) { - // ignore + } catch (Exception ignore) { } } diff --git a/src/test/java/org/springframework/data/redis/core/RedisTemplateIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/RedisTemplateIntegrationTests.java index 79f5e8ff4..755c4380c 100644 --- a/src/test/java/org/springframework/data/redis/core/RedisTemplateIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/RedisTemplateIntegrationTests.java @@ -351,6 +351,7 @@ public class RedisTemplateIntegrationTests { V value1 = valueFactory.instance(); List pipelinedResults = redisTemplate.executePipelined(new SessionCallback() { public Object execute(RedisOperations operations) throws DataAccessException { + operations.multi(); operations.opsForList().leftPush(key1, value1); operations.opsForList().rightPop(key1); @@ -360,9 +361,12 @@ public class RedisTemplateIntegrationTests { try { // Await EXEC completion as it's executed on a dedicated connection. Thread.sleep(100); - } catch (InterruptedException e) {} + } catch (InterruptedException ignore) { + } + operations.opsForValue().set(key1, value1); operations.opsForValue().get(key1); + return null; } }); @@ -719,7 +723,8 @@ public class RedisTemplateIntegrationTests { th.start(); try { th.join(); - } catch (InterruptedException e) {} + } catch (InterruptedException ignore) { + } operations.multi(); operations.opsForValue().set(key1, value3); @@ -751,7 +756,8 @@ public class RedisTemplateIntegrationTests { th.start(); try { th.join(); - } catch (InterruptedException e) {} + } catch (InterruptedException ignore) { + } operations.unwatch(); operations.multi(); @@ -788,7 +794,8 @@ public class RedisTemplateIntegrationTests { th.start(); try { th.join(); - } catch (InterruptedException e) {} + } catch (InterruptedException ignore) { + } operations.multi(); operations.opsForValue().set(key1, value3); diff --git a/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisAvailableCondition.java b/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisAvailableCondition.java index 731c82217..0b3e29c17 100644 --- a/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisAvailableCondition.java +++ b/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisAvailableCondition.java @@ -54,13 +54,14 @@ class EnabledOnRedisAvailableCondition implements ExecutionCondition { EnabledOnRedisAvailable annotation = optional.get(); try (Socket socket = new Socket()) { + socket.connect(new InetSocketAddress(SettingsUtils.getHost(), annotation.value()), 100); - return enabled( - String.format("Connection successful to Redis at %s:%d", SettingsUtils.getHost(), annotation.value())); - } catch (IOException e) { - return disabled( - String.format("Cannot connect to Redis at %s:%d (%s)", SettingsUtils.getHost(), annotation.value(), e)); + return enabled(String.format("Connection successful to Redis at %s:%d", SettingsUtils.getHost(), + annotation.value())); + } catch (IOException ex) { + return disabled(String.format("Cannot connect to Redis at %s:%d (%s)", SettingsUtils.getHost(), + annotation.value(), ex)); } } diff --git a/src/test/java/org/springframework/data/redis/test/condition/RedisConditions.java b/src/test/java/org/springframework/data/redis/test/condition/RedisConditions.java index 12bbe8039..c63a79808 100644 --- a/src/test/java/org/springframework/data/redis/test/condition/RedisConditions.java +++ b/src/test/java/org/springframework/data/redis/test/condition/RedisConditions.java @@ -57,8 +57,8 @@ class RedisConditions { p.load(inputStream); version = Version.parse(p.getProperty("redis_version")); - } catch (IOException e) { - throw new IllegalStateException(e); + } catch (IOException ex) { + throw new IllegalStateException(ex); } } diff --git a/src/test/java/org/springframework/data/redis/test/condition/RedisDetector.java b/src/test/java/org/springframework/data/redis/test/condition/RedisDetector.java index 3bef7b901..5413a35e3 100644 --- a/src/test/java/org/springframework/data/redis/test/condition/RedisDetector.java +++ b/src/test/java/org/springframework/data/redis/test/condition/RedisDetector.java @@ -39,7 +39,7 @@ public class RedisDetector { cluster.getConnectionFromSlot(1).close(); return true; - } catch (Exception e) { + } catch (Exception ignore) { return false; } }); @@ -54,9 +54,8 @@ public class RedisDetector { socket.connect(new InetSocketAddress(SettingsUtils.getHost(), port), 100); return true; - } catch (IOException e) { + } catch (IOException ignore) { return false; } } - } diff --git a/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedRedisTestExtension.java b/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedRedisTestExtension.java index 2f1128d13..fe4ace599 100644 --- a/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedRedisTestExtension.java +++ b/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedRedisTestExtension.java @@ -147,8 +147,8 @@ class ParameterizedRedisTestExtension implements TestTemplateInvocationContextPr protected static Stream arguments(ArgumentsProvider provider, ExtensionContext context) { try { return provider.provideArguments(context); - } catch (Exception e) { - throw ExceptionUtils.throwAsUncheckedException(e); + } catch (Exception ex) { + throw ExceptionUtils.throwAsUncheckedException(ex); } }