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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -158,8 +158,8 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
|
||||
public List<RedisServer> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ class StreamConverters {
|
||||
|
||||
try {
|
||||
return NumberUtils.parseNumber(tmp, Long.class);
|
||||
} catch (NumberFormatException e) {
|
||||
} catch (NumberFormatException ex) {
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -344,9 +344,11 @@ class DefaultReactiveStreamOperations<K, HK, HV> 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<K, HK, HV> implements ReactiveStreamOperat
|
||||
|
||||
try {
|
||||
return serializationContext.getHashValueSerializationPair().write(value);
|
||||
} catch (IllegalStateException ignore) {}
|
||||
} catch (IllegalStateException ignore) {
|
||||
}
|
||||
|
||||
return ByteBuffer.wrap(objectMapper.getConversionService().convert(value, byte[].class));
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ class DefaultValueOperations<K, V> extends AbstractOperations<K, V> 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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -685,7 +685,7 @@ public class RedisTemplate<K, V> 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<K, V> 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<K, V> 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);
|
||||
}
|
||||
|
||||
@@ -88,13 +88,13 @@ public abstract class ScanCursor<T> implements Cursor<T> {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)));
|
||||
|
||||
@@ -306,9 +306,9 @@ public class Bucket {
|
||||
|
||||
try {
|
||||
return new String(raw, CHARSET);
|
||||
} catch (Exception e) {
|
||||
// Ignore this one
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -571,8 +571,7 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
|
||||
PersistentPropertyPath<RedisPersistentProperty> persistentPropertyPath = mappingContext
|
||||
.getPersistentPropertyPath(path, type);
|
||||
return persistentPropertyPath.getLeafProperty();
|
||||
} catch (Exception e) {
|
||||
// that's just fine
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -240,15 +240,18 @@ public class RedisMappingContext extends KeyValueMappingContext<RedisPersistentE
|
||||
if (timeout != null && ttl != null) {
|
||||
return TimeUnit.SECONDS.convert(timeout.longValue(), ttl.unit());
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalStateException(
|
||||
"Not allowed to access method '" + timeoutMethod.getName() + "': " + e.getMessage(), e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot invoke method '" + timeoutMethod.getName() + " without arguments': " + e.getMessage(), e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new IllegalStateException("Cannot access method '" + timeoutMethod.getName() + "': " + e.getMessage(),
|
||||
e);
|
||||
} catch (IllegalAccessException ex) {
|
||||
String message = String.format("Not allowed to access method '%s': %s",
|
||||
timeoutMethod.getName(), ex.getMessage());
|
||||
throw new IllegalStateException(message, ex);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
String message = String.format("Cannot invoke method '%s' without arguments: %s",
|
||||
timeoutMethod.getName(), ex.getMessage());
|
||||
throw new IllegalStateException(message, ex);
|
||||
} catch (InvocationTargetException ex) {
|
||||
String message = String.format("Cannot access method '%s': %s",
|
||||
timeoutMethod.getName(), ex.getMessage());
|
||||
throw new IllegalStateException(message, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,8 +93,8 @@ public class DefaultRedisScript<T> implements RedisScript<T>, 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,10 +75,11 @@ public class DefaultScriptExecutor<K> implements ScriptExecutor<K> {
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class BeanUtilsHashMapper<T> implements HashMapper<T, String, String> {
|
||||
|
||||
return result;
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalArgumentException("Cannot describe object " + object, ex);
|
||||
throw new IllegalArgumentException(String.format("Cannot describe object %s", object), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,8 +264,8 @@ public class Jackson2HashMapper implements HashMapper<Object, String, Object> {
|
||||
|
||||
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<Object, String, Object> {
|
||||
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<Object, String, Object> {
|
||||
|
||||
try {
|
||||
return ctxt.getConfig().getDateFormat().parse(value.toString());
|
||||
} catch (ParseException cause) {
|
||||
} catch (ParseException ignore) {
|
||||
return new Date(NumberUtils.parseNumber(value.toString(), Long.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,8 +87,8 @@ public class RedisKeyValueAdapterBean extends CdiBean<RedisKeyValueAdapter> {
|
||||
if (instance instanceof DisposableBean) {
|
||||
try {
|
||||
instance.destroy();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ public class RedisKeyValueTemplateBean extends CdiBean<KeyValueOperations> {
|
||||
try {
|
||||
((DisposableBean) instance.getMappingContext()).destroy();
|
||||
instance.destroy();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -218,9 +218,9 @@ public class GenericJackson2JsonRedisSerializer implements RedisSerializer<Objec
|
||||
|
||||
try {
|
||||
return writer.write(mapper, value);
|
||||
} catch (IOException cause) {
|
||||
String message = String.format("Could not write JSON: %s", cause.getMessage());
|
||||
throw new SerializationException(message, cause);
|
||||
} catch (IOException ex) {
|
||||
String message = String.format("Could not write JSON: %s", ex.getMessage());
|
||||
throw new SerializationException(message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,9 +248,9 @@ public class GenericJackson2JsonRedisSerializer implements RedisSerializer<Objec
|
||||
|
||||
try {
|
||||
return (T) reader.read(mapper, source, resolveType(source, type));
|
||||
} catch (Exception cause) {
|
||||
String message = String.format("Could not read JSON:%s ", cause.getMessage());
|
||||
throw new SerializationException(message, cause);
|
||||
} catch (Exception ex) {
|
||||
String message = String.format("Could not read JSON:%s ", ex.getMessage());
|
||||
throw new SerializationException(message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,8 +81,8 @@ public class JdkSerializationRedisSerializer implements RedisSerializer<Object>
|
||||
|
||||
try {
|
||||
return serializer.convert(value);
|
||||
} catch (Exception cause) {
|
||||
throw new SerializationException("Cannot serialize", cause);
|
||||
} catch (Exception ex) {
|
||||
throw new SerializationException("Cannot serialize", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -326,8 +326,8 @@ class DefaultStreamReceiver<K, V extends Record<K, ?>> 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());
|
||||
|
||||
@@ -127,17 +127,17 @@ class StreamPollTask<K, V extends Record<K, ?>> implements Task {
|
||||
List<ByteRecord> 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<K, V extends Record<K, ?>> 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<K, V extends Record<K, ?>> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -100,8 +100,8 @@ public class ScanTests {
|
||||
cursorMap.next();
|
||||
}
|
||||
cursorMap.close();
|
||||
} catch (Exception e) {
|
||||
exception.set(e);
|
||||
} catch (Exception ex) {
|
||||
exception.set(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -224,8 +224,8 @@ public class JedisConnectionFactoryExtension implements ParameterResolver {
|
||||
try {
|
||||
mayClose = true;
|
||||
destroy();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,8 @@ public class DefaultSetOperationsIntegrationTests<K, V> {
|
||||
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<K, V> {
|
||||
try {
|
||||
setOps.distinctRandomMembers(keyFactory.instance(), -2);
|
||||
fail("IllegalArgumentException should be thrown");
|
||||
} catch (IllegalArgumentException e) {}
|
||||
} catch (IllegalArgumentException expected) {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -97,14 +97,10 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
|
||||
@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<K, V> {
|
||||
@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();
|
||||
}
|
||||
|
||||
|
||||
@@ -102,8 +102,7 @@ public class RedisKeyValueAdapterTests {
|
||||
|
||||
try {
|
||||
adapter.destroy();
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -351,6 +351,7 @@ public class RedisTemplateIntegrationTests<K, V> {
|
||||
V value1 = valueFactory.instance();
|
||||
List<Object> 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<K, V> {
|
||||
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<K, V> {
|
||||
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<K, V> {
|
||||
th.start();
|
||||
try {
|
||||
th.join();
|
||||
} catch (InterruptedException e) {}
|
||||
} catch (InterruptedException ignore) {
|
||||
}
|
||||
|
||||
operations.unwatch();
|
||||
operations.multi();
|
||||
@@ -788,7 +794,8 @@ public class RedisTemplateIntegrationTests<K, V> {
|
||||
th.start();
|
||||
try {
|
||||
th.join();
|
||||
} catch (InterruptedException e) {}
|
||||
} catch (InterruptedException ignore) {
|
||||
}
|
||||
|
||||
operations.multi();
|
||||
operations.opsForValue().set(key1, value3);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -147,8 +147,8 @@ class ParameterizedRedisTestExtension implements TestTemplateInvocationContextPr
|
||||
protected static Stream<? extends Arguments> arguments(ArgumentsProvider provider, ExtensionContext context) {
|
||||
try {
|
||||
return provider.provideArguments(context);
|
||||
} catch (Exception e) {
|
||||
throw ExceptionUtils.throwAsUncheckedException(e);
|
||||
} catch (Exception ex) {
|
||||
throw ExceptionUtils.throwAsUncheckedException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user