From e828bbbb0a7748fc0c3b9ca00ec77daac5c622ac Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 24 Jun 2025 22:22:45 +0200 Subject: [PATCH] Invert order of suppressed exceptions (for common exception rendering) See gh-35057 --- .../java/org/springframework/core/retry/RetryTemplate.java | 5 +---- .../org/springframework/core/retry/RetryTemplateTests.java | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/retry/RetryTemplate.java b/spring-core/src/main/java/org/springframework/core/retry/RetryTemplate.java index c8e8ea18b73..6e782843943 100644 --- a/spring-core/src/main/java/org/springframework/core/retry/RetryTemplate.java +++ b/spring-core/src/main/java/org/springframework/core/retry/RetryTemplate.java @@ -19,7 +19,6 @@ package org.springframework.core.retry; import java.time.Duration; import java.util.ArrayDeque; import java.util.Deque; -import java.util.Iterator; import org.jspecify.annotations.Nullable; @@ -203,9 +202,7 @@ public class RetryTemplate implements RetryOperations { RetryException finalException = new RetryException( "Retry policy for operation '%s' exhausted; aborting execution".formatted(retryableName), exceptions.removeLast()); - for (Iterator it = exceptions.descendingIterator(); it.hasNext();) { - finalException.addSuppressed(it.next()); - } + exceptions.forEach(finalException::addSuppressed); this.retryListener.onRetryPolicyExhaustion(retryExecution, finalException); throw finalException; } diff --git a/spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java b/spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java index 6d431bdff0f..4772626efb3 100644 --- a/spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java +++ b/spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java @@ -178,8 +178,8 @@ class RetryTemplateTests { .withMessage("Retry policy for operation 'test' exhausted; aborting execution") .withCauseExactlyInstanceOf(IllegalStateException.class) .satisfies(hasSuppressedExceptionsSatisfyingExactly( - suppressed1 -> assertThat(suppressed1).isExactlyInstanceOf(IOException.class), - suppressed2 -> assertThat(suppressed2).isExactlyInstanceOf(FileNotFoundException.class) + suppressed1 -> assertThat(suppressed1).isExactlyInstanceOf(FileNotFoundException.class), + suppressed2 -> assertThat(suppressed2).isExactlyInstanceOf(IOException.class) )); // 3 = 1 initial invocation + 2 retry attempts assertThat(invocationCount).hasValue(3);