Skip to content

Commit e828bbb

Browse files
committed
Invert order of suppressed exceptions (for common exception rendering)
See gh-35057
1 parent 90c8751 commit e828bbb

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.time.Duration;
2020
import java.util.ArrayDeque;
2121
import java.util.Deque;
22-
import java.util.Iterator;
2322

2423
import org.jspecify.annotations.Nullable;
2524

@@ -203,9 +202,7 @@ public void setRetryListener(RetryListener retryListener) {
203202
RetryException finalException = new RetryException(
204203
"Retry policy for operation '%s' exhausted; aborting execution".formatted(retryableName),
205204
exceptions.removeLast());
206-
for (Iterator<Throwable> it = exceptions.descendingIterator(); it.hasNext();) {
207-
finalException.addSuppressed(it.next());
208-
}
205+
exceptions.forEach(finalException::addSuppressed);
209206
this.retryListener.onRetryPolicyExhaustion(retryExecution, finalException);
210207
throw finalException;
211208
}

spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ public String getName() {
178178
.withMessage("Retry policy for operation 'test' exhausted; aborting execution")
179179
.withCauseExactlyInstanceOf(IllegalStateException.class)
180180
.satisfies(hasSuppressedExceptionsSatisfyingExactly(
181-
suppressed1 -> assertThat(suppressed1).isExactlyInstanceOf(IOException.class),
182-
suppressed2 -> assertThat(suppressed2).isExactlyInstanceOf(FileNotFoundException.class)
181+
suppressed1 -> assertThat(suppressed1).isExactlyInstanceOf(FileNotFoundException.class),
182+
suppressed2 -> assertThat(suppressed2).isExactlyInstanceOf(IOException.class)
183183
));
184184
// 3 = 1 initial invocation + 2 retry attempts
185185
assertThat(invocationCount).hasValue(3);

0 commit comments

Comments
 (0)