Browse Source

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
pull/35335/head
Stéphane Nicoll 4 months ago
parent
commit
532911eb93
  1. 3
      spring-context/src/main/java/org/springframework/resilience/retry/AbstractRetryInterceptor.java
  2. 17
      spring-core/src/main/java/org/springframework/core/retry/RetryException.java

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

@ -112,8 +112,7 @@ public abstract class AbstractRetryInterceptor implements MethodInterceptor { @@ -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
spring-core/src/main/java/org/springframework/core/retry/RetryException.java

@ -17,6 +17,9 @@ @@ -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 { @@ -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 { @@ -48,4 +43,10 @@ public class RetryException extends Exception {
super(message, cause);
}
@Override
public synchronized @NonNull Throwable getCause() {
return Objects.requireNonNull(super.getCause());
}
}

Loading…
Cancel
Save