Skip to content

Commit 9d57dab

Browse files
committed
Rename exception variables to clarify intent
1 parent ed2fb61 commit 9d57dab

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

spring-core/src/main/java/org/springframework/core/retry/RetryTemplate.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ public void setRetryListener(RetryListener retryListener) {
133133
Deque<Throwable> exceptions = new ArrayDeque<>();
134134
exceptions.add(initialException);
135135

136-
Throwable retryException = initialException;
137-
while (this.retryPolicy.shouldRetry(retryException)) {
136+
Throwable lastException = initialException;
137+
while (this.retryPolicy.shouldRetry(lastException)) {
138138
try {
139139
long duration = backOffExecution.nextBackOff();
140140
if (duration == BackOffExecution.STOP) {
@@ -159,23 +159,23 @@ public void setRetryListener(RetryListener retryListener) {
159159
.formatted(retryableName));
160160
return result;
161161
}
162-
catch (Throwable currentAttemptException) {
162+
catch (Throwable currentException) {
163163
logger.debug(() -> "Retry attempt for operation '%s' failed due to '%s'"
164-
.formatted(retryableName, currentAttemptException));
165-
this.retryListener.onRetryFailure(this.retryPolicy, retryable, currentAttemptException);
166-
exceptions.add(currentAttemptException);
167-
retryException = currentAttemptException;
164+
.formatted(retryableName, currentException));
165+
this.retryListener.onRetryFailure(this.retryPolicy, retryable, currentException);
166+
exceptions.add(currentException);
167+
lastException = currentException;
168168
}
169169
}
170170

171171
// The RetryPolicy has exhausted at this point, so we throw a RetryException with the
172-
// initial exception as the cause and remaining exceptions as suppressed exceptions.
173-
RetryException finalException = new RetryException(
172+
// last exception as the cause and remaining exceptions as suppressed exceptions.
173+
RetryException retryException = new RetryException(
174174
"Retry policy for operation '%s' exhausted; aborting execution".formatted(retryableName),
175175
exceptions.removeLast());
176-
exceptions.forEach(finalException::addSuppressed);
177-
this.retryListener.onRetryPolicyExhaustion(this.retryPolicy, retryable, retryException);
178-
throw finalException;
176+
exceptions.forEach(retryException::addSuppressed);
177+
this.retryListener.onRetryPolicyExhaustion(this.retryPolicy, retryable, lastException);
178+
throw retryException;
179179
}
180180
}
181181

0 commit comments

Comments
 (0)