Skip to content

Commit 03817c3

Browse files
committed
Fix the retry condition to just look for the initial cause
1 parent c434b26 commit 03817c3

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

core/retries-api/src/main/java/software/amazon/awssdk/retries/api/RetryStrategy.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,10 @@ default B retryOnExceptionOrCause(Class<? extends Throwable> throwable) {
127127
return true;
128128
}
129129
Throwable cause = t.getCause();
130-
while (cause != null) {
130+
if (cause != null) {
131131
if (cause.getClass() == throwable) {
132132
return true;
133133
}
134-
cause = cause.getCause();
135134
}
136135
return false;
137136
});
@@ -147,11 +146,10 @@ default B retryOnExceptionOrCauseInstanceOf(Class<? extends Throwable> throwable
147146
return true;
148147
}
149148
Throwable cause = t.getCause();
150-
while (cause != null) {
149+
if (cause != null) {
151150
if (throwable.isAssignableFrom(cause.getClass())) {
152151
return true;
153152
}
154-
cause = cause.getCause();
155153
}
156154
return false;
157155
});

core/retries-api/src/test/java/software/amazon/awssdk/retries/api/RetryStrategyBuilderTest.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ static Collection<TestCase> parameters() {
5858
.expectShouldRetry()
5959
, new TestCase()
6060
.configure(b -> b.retryOnExceptionOrCause(IllegalArgumentException.class))
61-
.givenThrowable(new RuntimeException(new RuntimeException(new IllegalArgumentException())))
62-
.expectShouldRetry()
63-
, new TestCase()
64-
.configure(b -> b.retryOnExceptionOrCause(IllegalArgumentException.class))
65-
.givenThrowable(new RuntimeException(new RuntimeException(new NumberFormatException())))
61+
.givenThrowable(new RuntimeException(new NumberFormatException()))
6662
.expectShouldNotRetry()
6763
, new TestCase()
6864
.configure(b -> b.retryOnExceptionInstanceOf(IllegalArgumentException.class))
@@ -96,10 +92,6 @@ static Collection<TestCase> parameters() {
9692
.configure(b -> b.retryOnExceptionOrCauseInstanceOf(IllegalArgumentException.class))
9793
.givenThrowable(new NumberFormatException())
9894
.expectShouldRetry()
99-
, new TestCase()
100-
.configure(b -> b.retryOnExceptionOrCauseInstanceOf(IllegalArgumentException.class))
101-
.givenThrowable(new RuntimeException(new RuntimeException(new NumberFormatException())))
102-
.expectShouldRetry()
10395
);
10496
}
10597

0 commit comments

Comments
 (0)