From f5564e7e31e157c5a5fe6971684a1b271f39da06 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 31 Jul 2026 16:27:18 +0200 Subject: [PATCH] Consistently use default constants within builder See gh-36983 --- .../core/retry/RetryPolicy.java | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/retry/RetryPolicy.java b/spring-core/src/main/java/org/springframework/core/retry/RetryPolicy.java index adb92e90148..fd913820574 100644 --- a/spring-core/src/main/java/org/springframework/core/retry/RetryPolicy.java +++ b/spring-core/src/main/java/org/springframework/core/retry/RetryPolicy.java @@ -157,6 +157,12 @@ public interface RetryPolicy { */ public static final long DEFAULT_DELAY = 1000; + /** + * The default {@linkplain #jitter(Duration) jitter}: {@value}. + * @since 7.0.9 + */ + public static final long DEFAULT_JITTER = 0; + /** * The default {@linkplain #multiplier(double) multiplier}: {@value}. */ @@ -179,8 +185,6 @@ public interface RetryPolicy { private @Nullable Long maxRetries; - private Duration timeout = Duration.ZERO; - private @Nullable Duration delay; private @Nullable Duration jitter; @@ -189,6 +193,8 @@ public interface RetryPolicy { private @Nullable Duration maxDelay; + private Duration timeout = DEFAULT_TIMEOUT; + private final Set> includes = new LinkedHashSet<>(); private final Set> excludes = new LinkedHashSet<>(); @@ -240,24 +246,6 @@ public interface RetryPolicy { return this; } - /** - * Specify a timeout for the maximum amount of elapsed time allowed for - * the initial invocation and any subsequent retry attempts, including - * delays. - *

The default is {@link Duration#ZERO}, which signals that no timeout - * should be applied. - *

The supplied value will override any previously configured value. - * @param timeout the timeout, typically in milliseconds or seconds; - * must be greater than or equal to zero - * @return this {@code Builder} instance for chained method invocations - * @since 7.0.2 - */ - public Builder timeout(Duration timeout) { - assertIsNotNegative("timeout", timeout); - this.timeout = timeout; - return this; - } - /** * Specify the base delay after the initial invocation. *

If a {@linkplain #multiplier(double) multiplier} is specified, this @@ -353,6 +341,24 @@ public interface RetryPolicy { return this; } + /** + * Specify a timeout for the maximum amount of elapsed time allowed for + * the initial invocation and any subsequent retry attempts, including + * delays. + *

The default is {@link Duration#ZERO}, which signals that no timeout + * should be applied. + *

The supplied value will override any previously configured value. + * @param timeout the timeout, typically in milliseconds or seconds; + * must be greater than or equal to zero + * @return this {@code Builder} instance for chained method invocations + * @since 7.0.2 + */ + public Builder timeout(Duration timeout) { + assertIsNotNegative("timeout", timeout); + this.timeout = timeout; + return this; + } + /** * Specify the types of exceptions for which the {@link RetryPolicy} * should retry a failed operation. @@ -483,11 +489,9 @@ public interface RetryPolicy { ExponentialBackOff exponentialBackOff = new ExponentialBackOff(); exponentialBackOff.setMaxAttempts(this.maxRetries != null ? this.maxRetries : DEFAULT_MAX_RETRIES); exponentialBackOff.setInitialInterval(this.delay != null ? this.delay.toMillis() : DEFAULT_DELAY); - exponentialBackOff.setMaxInterval(this.maxDelay != null ? this.maxDelay.toMillis() : DEFAULT_MAX_DELAY); + exponentialBackOff.setJitter(this.jitter != null ? this.jitter.toMillis() : DEFAULT_JITTER); exponentialBackOff.setMultiplier(this.multiplier != null ? this.multiplier : DEFAULT_MULTIPLIER); - if (this.jitter != null) { - exponentialBackOff.setJitter(this.jitter.toMillis()); - } + exponentialBackOff.setMaxInterval(this.maxDelay != null ? this.maxDelay.toMillis() : DEFAULT_MAX_DELAY); backOff = exponentialBackOff; } return new DefaultRetryPolicy(this.includes, this.excludes, this.predicate, this.timeout, backOff);