Skip to content

Copy includes and excludes in RetryPolicy.Builder - #37596

Merged
sbrannen merged 1 commit into
spring-projects:mainfrom
Tanishq-Choudhary:retry-policy-builder-copy
Oct 28, 2026
Merged

sbrannen merged 1 commit into
spring-projects:mainfrom
Tanishq-Choudhary:retry-policy-builder-copy

Conversation

@Tanishq-Choudhary

Copy link
Copy Markdown
Contributor

RetryPolicy.Builder#build() passes its own includes and excludes sets to the DefaultRetryPolicy, and InstanceFilter only wraps them in read-only views. So adding includes or excludes to the builder after build() changes what an already built policy retries:

RetryPolicy.Builder builder = RetryPolicy.builder().includes(IOException.class);
RetryPolicy policy = builder.build();
policy.shouldRetry(new IllegalStateException()); // false

builder.includes(IllegalStateException.class);
policy.shouldRetry(new IllegalStateException()); // true

The other settings don't have this problem, since build() turns them into a new BackOff. It is the same kind of issue that #37325 fixed for WebTestClient#build().

The fix copies the two sets in build(). The new test in RetryPolicyTests fails without it:

RetryPolicyTests > BuilderTests > includesAndExcludesNotChangedByBuilderAfterBuild() FAILED
    Expecting value to be true but was false

I ran ./gradlew :spring-core:check on Windows with JDK 25. The only failures were in ResourceRegionEncoderTests, PathMatchingResourcePatternResolverTests and DataBufferUtilsTests (which also hangs here), and they fail the same way on main on this machine.

Prior to this commit, RetryPolicy.Builder#build() passed its own
includes and excludes sets to DefaultRetryPolicy, which only wraps them
in read-only views. Adding includes or excludes to the builder after
build() therefore changed which exceptions an already built policy
retries. The back-off settings are not affected, since build() creates
a new BackOff from them.

This commit copies the includes and excludes in build().

Signed-off-by: Tanishq Choudhary <tanishqchoudhary007@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 26, 2026
@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 26, 2026
@sbrannen sbrannen self-assigned this Oct 26, 2026
@sbrannen sbrannen added this to the 7.1.0-RC2 milestone Oct 26, 2026
@sbrannen sbrannen changed the title Copy includes and excludes in RetryPolicy.Builder Copy includes and excludes in RetryPolicy.Builder Oct 26, 2026
@sbrannen
sbrannen merged commit b98ad3c into spring-projects:main Oct 28, 2026
1 check passed
sbrannen added a commit that referenced this pull request Oct 28, 2026
@sbrannen

sbrannen commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Hi @Tanishq-Choudhary,

Congratulations on submitting your first PR for the Spring Framework! 👍

This has been merged into main in b98ad3c and slightly revised in 4892cf7.

Thanks

sbrannen pushed a commit that referenced this pull request Nov 21, 2026
Prior to this commit, HandlerTypePredicate.Builder#build() passed its
own base packages, assignable types and annotations to the predicate,
which only wrapped them in read-only views. Changing the builder after
build() therefore also changed which handler types an already built
predicate matched.

This commit makes defensive copies in the HandlerTypePredicate
constructor, as DefaultRetryPolicy does since gh-37596.

Closes gh-37599

Signed-off-by: Tanishq Choudhary <tanishqchoudhary007@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants