Skip to content

Conversation

@ziqin
Copy link
Contributor

@ziqin ziqin commented Jan 11, 2026

Currently, the List-receiving constructors of AndRequestMatcher, OrRequestMatcher, AndServerWebExchangeMatcher, and OrServerWebExchangeMatcher don't support covariance, which adds obstacles to users of these APIs. For example, one cannot pass a List<PathPatternRequestMatcher> to OrRequestMatcher(List<RequestMatcher>).

This PR resolves the aforementioned problem. It should not break existing code.

Currently, the List-receiving constructors of AndRequestMatcher,
OrRequestMatcher, AndServerWebExchangeMatcher, and OrServerWebExchangeMatcher
don't support covariance, which adds obstacles to users of these
APIs.  For example, one cannot pass a List<PathPatternRequestMatcher>
to OrRequestMatcher(List<RequestMatcher>).

This commit resolves the aforementioned problem.  It should not
break existing code.

Signed-off-by: Ziqin Wang <[email protected]>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 11, 2026
@ziqin
Copy link
Contributor Author

ziqin commented Jan 16, 2026

I discovered this problem when working on PR #18499, where I had to explicitly specify the return of builder::matcher as the interface RequestMatcher so that I can get a List<RequestMatcher> instead of List<PathPatternRequestMatcher>.

public ContentSecurityPolicyConfig requireCspMatchers(String... pathPatterns) {
PathPatternRequestMatcher.Builder builder = HeadersConfigurer.this.getRequestMatcherBuilder();
// @formatter:off
return this.requireCspMatcher(new OrRequestMatcher(
Arrays.stream(pathPatterns)
.map((Function<? super String, RequestMatcher>) builder::matcher)
.toList()));
// @formatter:on
}

If this PR is merged, we can simply use Arrays.stream(pathPatterns).map(builder::matcher).toList().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants