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
This commit is contained in:
Stéphane Nicoll
2025-08-16 09:20:02 +02:00
parent 498b0c231b
commit 532911eb93
2 changed files with 10 additions and 10 deletions
@@ -112,8 +112,7 @@ public abstract class AbstractRetryInterceptor implements MethodInterceptor {
});
}
catch (RetryException ex) {
Throwable cause = ex.getCause();
throw (cause != null ? cause : new IllegalStateException(ex.getMessage(), ex));
throw ex.getCause();
}
}
@@ -17,6 +17,9 @@
package org.springframework.core.retry;
import java.io.Serial;
import java.util.Objects;
import org.jspecify.annotations.NonNull;
/**
* Exception thrown when a {@link RetryPolicy} has been exhausted.
@@ -31,14 +34,6 @@ public class RetryException extends Exception {
private static final long serialVersionUID = 5439915454935047936L;
/**
* Create a new {@code RetryException} for the supplied message.
* @param message the detail message
*/
public RetryException(String message) {
super(message);
}
/**
* Create a new {@code RetryException} for the supplied message and cause.
* @param message the detail message
@@ -48,4 +43,10 @@ public class RetryException extends Exception {
super(message, cause);
}
@Override
public synchronized @NonNull Throwable getCause() {
return Objects.requireNonNull(super.getCause());
}
}