Skip to content

Commit 532911e

Browse files
committed
Mark RetryException#getCause non null
This commit simplifies RetryException to always require a root cause and mark it as not nullable. Such exception is the exception thrown by the retryable operation and should always be available as it explains why the invocation was a candidate for retrying in the first place. Closes gh-35332
1 parent 498b0c2 commit 532911e

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

spring-context/src/main/java/org/springframework/resilience/retry/AbstractRetryInterceptor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ public String getName() {
112112
});
113113
}
114114
catch (RetryException ex) {
115-
Throwable cause = ex.getCause();
116-
throw (cause != null ? cause : new IllegalStateException(ex.getMessage(), ex));
115+
throw ex.getCause();
117116
}
118117
}
119118

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
package org.springframework.core.retry;
1818

1919
import java.io.Serial;
20+
import java.util.Objects;
21+
22+
import org.jspecify.annotations.NonNull;
2023

2124
/**
2225
* Exception thrown when a {@link RetryPolicy} has been exhausted.
@@ -31,14 +34,6 @@ public class RetryException extends Exception {
3134
private static final long serialVersionUID = 5439915454935047936L;
3235

3336

34-
/**
35-
* Create a new {@code RetryException} for the supplied message.
36-
* @param message the detail message
37-
*/
38-
public RetryException(String message) {
39-
super(message);
40-
}
41-
4237
/**
4338
* Create a new {@code RetryException} for the supplied message and cause.
4439
* @param message the detail message
@@ -48,4 +43,10 @@ public RetryException(String message, Throwable cause) {
4843
super(message, cause);
4944
}
5045

46+
47+
@Override
48+
public synchronized @NonNull Throwable getCause() {
49+
return Objects.requireNonNull(super.getCause());
50+
}
51+
5152
}

0 commit comments

Comments
 (0)