mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
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:
+1
-2
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user