Skip to content

Commit ff167aa

Browse files
committed
Make built-in RetryPolicy implementations final
Closes gh-35040
1 parent fb0fb21 commit ff167aa

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

spring-core/src/main/java/org/springframework/core/retry/support/MaxRetryAttemptsPolicy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* @author Sam Brannen
2828
* @since 7.0
2929
*/
30-
public class MaxRetryAttemptsPolicy implements RetryPolicy {
30+
public final class MaxRetryAttemptsPolicy implements RetryPolicy {
3131

3232
/**
3333
* The default maximum number of retry attempts: {@value}.

spring-core/src/main/java/org/springframework/core/retry/support/MaxRetryDurationPolicy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @author Sam Brannen
3131
* @since 7.0
3232
*/
33-
public class MaxRetryDurationPolicy implements RetryPolicy {
33+
public final class MaxRetryDurationPolicy implements RetryPolicy {
3434

3535
/**
3636
* The default maximum retry duration: 3 seconds.

spring-core/src/main/java/org/springframework/core/retry/support/PredicateRetryPolicy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @author Sam Brannen
2929
* @since 7.0
3030
*/
31-
public class PredicateRetryPolicy implements RetryPolicy {
31+
public final class PredicateRetryPolicy implements RetryPolicy {
3232

3333
private final Predicate<Throwable> predicate;
3434

spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import org.junit.jupiter.api.Test;
2222

23-
import org.springframework.core.retry.support.MaxRetryAttemptsPolicy;
2423
import org.springframework.util.backoff.FixedBackOff;
2524

2625
import static org.assertj.core.api.Assertions.assertThat;
@@ -110,20 +109,15 @@ public String getName() {
110109
}
111110
};
112111

113-
MaxRetryAttemptsPolicy retryPolicy = new MaxRetryAttemptsPolicy() {
114-
@Override
115-
public RetryExecution start() {
116-
return new RetryExecution() {
117-
118-
int retryAttempts;
112+
RetryPolicy retryPolicy = () -> new RetryExecution() {
113+
int retryAttempts;
119114

120-
@Override
121-
public boolean shouldRetry(Throwable throwable) {
122-
return this.retryAttempts++ < 3 && throwable instanceof TechnicalException;
123-
}
124-
};
115+
@Override
116+
public boolean shouldRetry(Throwable throwable) {
117+
return (this.retryAttempts++ < 3 && throwable instanceof TechnicalException);
125118
}
126119
};
120+
127121
retryTemplate.setRetryPolicy(retryPolicy);
128122
retryTemplate.setBackOffPolicy(new FixedBackOff(Duration.ofMillis(10)));
129123

0 commit comments

Comments
 (0)