Skip to content

Apply consistent Exception variable names to all catch blocks #2749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-GH-2748-SNAPSHOT</version>

<name>Spring Data Redis</name>
<description>Spring Data module for Redis</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,14 @@ private void checkAndPotentiallyWaitUntilUnlocked(String name, RedisConnection c
while (doCheckLock(name, connection)) {
Thread.sleep(this.sleepTime.toMillis());
}
} catch (InterruptedException cause) {
} catch (InterruptedException ex) {

// 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),
cause);
String message = String.format("Interrupted while waiting to unlock cache %s", name);

throw new PessimisticLockingFailureException(message, ex);
} finally {
this.statistics.incLockTime(name, System.nanoTime() - lockWaitTimeNs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ protected <T> T loadCacheValue(Object key, Callable<T> valueLoader) {

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);
Expand Down Expand Up @@ -425,14 +425,14 @@ protected String convertKey(Object key) {
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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public void close() throws DataAccessException {

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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ private <S, T> NodeResult<T> executeCommandOnSingleNode(ClusterCommandCallback<S

if (redirectCount > this.maxRedirects) {

throw new TooManyClusterRedirectionsException(String.format(
"Cannot follow Cluster Redirects over more than %s legs; "
+ "Consider increasing the number of redirects to follow; Current value is: %s.",
redirectCount, this.maxRedirects));
String message = String.format("Cannot follow Cluster Redirects over more than %s legs; "
+ "Consider increasing the number of redirects to follow; Current value is: %s.",
redirectCount, this.maxRedirects);

throw new TooManyClusterRedirectionsException(message);
}

RedisClusterNode nodeToUse = lookupNode(node);
Expand All @@ -145,15 +146,19 @@ private <S, T> NodeResult<T> executeCommandOnSingleNode(ClusterCommandCallback<S

try {
return new NodeResult<>(node, commandCallback.doInCluster(client));
} catch (RuntimeException cause) {
} catch (RuntimeException ex) {

RuntimeException translatedException = convertToDataAccessException(cause);
RuntimeException translatedException = convertToDataAccessException(ex);

if (translatedException instanceof ClusterRedirectException clusterRedirectException) {
return executeCommandOnSingleNode(commandCallback, topologyProvider.getTopology().lookup(
clusterRedirectException.getTargetHost(), clusterRedirectException.getTargetPort()), redirectCount + 1);

String targetHost = clusterRedirectException.getTargetHost();
int targetPort = clusterRedirectException.getTargetPort();
RedisClusterNode clusterNode = topologyProvider.getTopology().lookup(targetHost, targetPort);

return executeCommandOnSingleNode(commandCallback, clusterNode, redirectCount + 1);
} else {
throw translatedException != null ? translatedException : cause;
throw translatedException != null ? translatedException : ex;
}
} finally {
this.resourceProvider.returnResourceForSpecificNode(nodeToUse, client);
Expand All @@ -172,8 +177,8 @@ private RedisClusterNode lookupNode(RedisClusterNode node) {

try {
return topologyProvider.getTopology().lookup(node);
} catch (ClusterStateFailureException cause) {
throw new IllegalArgumentException(String.format("Node %s is unknown to cluster", node), cause);
} catch (ClusterStateFailureException ex) {
throw new IllegalArgumentException(String.format("Node %s is unknown to cluster", node), ex);
}
}

Expand Down Expand Up @@ -209,8 +214,8 @@ public <S, T> MultiNodeResult<T> executeCommandAsyncOnNodes(ClusterCommandCallba
for (RedisClusterNode node : nodes) {
try {
resolvedRedisClusterNodes.add(topology.lookup(node));
} catch (ClusterStateFailureException cause) {
throw new IllegalArgumentException(String.format("Node %s is unknown to cluster", node), cause);
} catch (ClusterStateFailureException ex) {
throw new IllegalArgumentException(String.format("Node %s is unknown to cluster", node), ex);
}
}

Expand Down Expand Up @@ -249,13 +254,13 @@ <T> MultiNodeResult<T> collectResults(Map<NodeExecution, Future<NodeResult<T>>>
}

entryIterator.remove();
} catch (ExecutionException exception) {
} catch (ExecutionException ex) {
entryIterator.remove();
exceptionCollector.addException(nodeExecution, exception.getCause());
exceptionCollector.addException(nodeExecution, ex.getCause());
} catch (TimeoutException ignore) {
} catch (InterruptedException exception) {
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
exceptionCollector.addException(nodeExecution, exception);
exceptionCollector.addException(nodeExecution, ex);
break OUT;
}
}
Expand Down Expand Up @@ -316,11 +321,11 @@ private <S, T> NodeResult<T> executeMultiKeyCommandOnSingleNode(MultiKeyClusterC

try {
return new NodeResult<>(node, commandCallback.doInCluster(client, key), key);
} catch (RuntimeException cause) {
} catch (RuntimeException ex) {

RuntimeException translatedException = convertToDataAccessException(cause);
RuntimeException translatedException = convertToDataAccessException(ex);

throw translatedException != null ? translatedException : cause;
throw translatedException != null ? translatedException : ex;
} finally {
this.resourceProvider.returnResourceForSpecificNode(node, client);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static RedisNode fromString(String hostPortString) {
int port = -1;
try {
port = Integer.parseInt(portString);
} catch (RuntimeException e) {
} catch (RuntimeException ignore) {
throw new IllegalArgumentException(String.format("Unparseable port number: %s", hostPortString));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public static Properties toProperties(String source) {

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public JedisClusterConnection(JedisCluster cluster) {
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

// ignore and work with the executor default
}
}

Expand Down Expand Up @@ -381,8 +381,8 @@ public void subscribe(MessageListener listener, byte[]... channels) {
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);
}
}

Expand All @@ -398,8 +398,8 @@ public void pSubscribe(MessageListener listener, byte[]... patterns) {
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);
}
}

Expand Down Expand Up @@ -643,8 +643,8 @@ public void close() throws DataAccessException {
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);
}
}

Expand Down Expand Up @@ -864,8 +864,8 @@ public ClusterTopology getTopology() {

return cached;

} catch (Exception cause) {
errors.put(entry.getKey(), cause);
} catch (Exception ex) {
errors.put(entry.getKey(), ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ protected JedisConnection(Jedis jedis, @Nullable Pool<Jedis> pool, JedisClientCo
if (nodeConfig.getDatabase() != jedis.getDB()) {
try {
select(nodeConfig.getDatabase());
} catch (DataAccessException cause) {
} catch (DataAccessException ex) {
close();
throw cause;
throw ex;
}
}
}
Expand Down Expand Up @@ -413,17 +413,17 @@ private List<Object> convertPipelineResults() {
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);
}
}

Expand Down Expand Up @@ -488,8 +488,8 @@ public List<Object> exec() {
? new TransactionResultConverter<>(txResults, JedisExceptionConverter.INSTANCE).convert(results)
: results;

} catch (Exception cause) {
throw convertJedisAccessException(cause);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
} finally {
txResults.clear();
transaction = null;
Expand Down Expand Up @@ -684,7 +684,7 @@ protected boolean isActive(RedisNode node) {
verification = getJedis(node);
verification.connect();
return verification.ping().equalsIgnoreCase("pong");
} catch (Exception cause) {
} catch (Exception ignore) {
return false;
} finally {
if (verification != null) {
Expand All @@ -708,17 +708,17 @@ private <T> T doWithJedis(Function<Jedis, T> callback) {

try {
return callback.apply(getJedis());
} catch (Exception cause) {
throw convertJedisAccessException(cause);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}

private void doWithJedis(Consumer<Jedis> callback) {

try {
callback.accept(getJedis());
} catch (Exception cause) {
throw convertJedisAccessException(cause);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}

Expand All @@ -727,9 +727,9 @@ private void doExceptionThrowingOperationSafely(ExceptionThrowingOperation opera
try {
operation.run();
}
catch (Exception cause) {
catch (Exception ex) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(logMessage, cause);
LOGGER.debug(logMessage, ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,8 @@ public void stop() {
try {
clusterCommandExecutor.destroy();
this.clusterCommandExecutor = null;
} catch (Exception cause) {
throw new RuntimeException(cause);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}

Expand All @@ -715,8 +715,8 @@ public void stop() {
try {
this.cluster.close();
this.cluster = null;
} catch (Exception cause) {
log.warn("Cannot properly close Jedis cluster", cause);
} catch (Exception ex) {
log.warn("Cannot properly close Jedis cluster", ex);
}
}

Expand Down Expand Up @@ -869,8 +869,8 @@ protected Jedis fetchJedisConnector() {
jedis.connect();

return jedis;
} catch (Exception cause) {
throw new RedisConnectionFailureException("Cannot get Jedis connection", cause);
} catch (Exception ex) {
throw new RedisConnectionFailureException("Cannot get Jedis connection", ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ public Long clusterCountKeysInSlot(int slot) {

try {
return getConnection().clusterCountKeysInSlot(slot);
} catch (Exception cause) {
throw this.exceptionConverter.translate(cause);
} catch (Exception ex) {
throw this.exceptionConverter.translate(ex);
}
}

Expand Down Expand Up @@ -453,8 +453,8 @@ public List<byte[]> clusterGetKeysInSlot(int slot, Integer count) {

try {
return getConnection().clusterGetKeysInSlot(slot, count);
} catch (Exception cause) {
throw this.exceptionConverter.translate(cause);
} catch (Exception ex) {
throw this.exceptionConverter.translate(ex);
}
}

Expand Down
Loading