Improve And/Or-RequestMatcher/ServerWebExchangeMatcher API

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 <ziqin@wangziqin.net>
This commit is contained in:
Ziqin Wang 2026-01-11 18:21:02 +08:00 committed by Josh Cummings
parent 46e27aa693
commit acbf64a47d
4 changed files with 8 additions and 8 deletions

View File

@ -42,9 +42,9 @@ public class AndServerWebExchangeMatcher implements ServerWebExchangeMatcher {
private static final Log logger = LogFactory.getLog(AndServerWebExchangeMatcher.class);
private final List<ServerWebExchangeMatcher> matchers;
private final List<? extends ServerWebExchangeMatcher> matchers;
public AndServerWebExchangeMatcher(List<ServerWebExchangeMatcher> matchers) {
public AndServerWebExchangeMatcher(List<? extends ServerWebExchangeMatcher> matchers) {
Assert.notEmpty(matchers, "matchers cannot be empty");
this.matchers = matchers;
}

View File

@ -40,9 +40,9 @@ public class OrServerWebExchangeMatcher implements ServerWebExchangeMatcher {
private static final Log logger = LogFactory.getLog(OrServerWebExchangeMatcher.class);
private final List<ServerWebExchangeMatcher> matchers;
private final List<? extends ServerWebExchangeMatcher> matchers;
public OrServerWebExchangeMatcher(List<ServerWebExchangeMatcher> matchers) {
public OrServerWebExchangeMatcher(List<? extends ServerWebExchangeMatcher> matchers) {
Assert.notEmpty(matchers, "matchers cannot be empty");
this.matchers = matchers;
}

View File

@ -36,13 +36,13 @@ import org.springframework.util.Assert;
*/
public final class AndRequestMatcher implements RequestMatcher {
private final List<RequestMatcher> requestMatchers;
private final List<? extends RequestMatcher> requestMatchers;
/**
* Creates a new instance
* @param requestMatchers the {@link RequestMatcher} instances to try
*/
public AndRequestMatcher(List<RequestMatcher> requestMatchers) {
public AndRequestMatcher(List<? extends RequestMatcher> requestMatchers) {
Assert.notEmpty(requestMatchers, "requestMatchers must contain a value");
Assert.noNullElements(requestMatchers, "requestMatchers cannot contain null values");
this.requestMatchers = requestMatchers;

View File

@ -34,13 +34,13 @@ import org.springframework.util.Assert;
*/
public final class OrRequestMatcher implements RequestMatcher {
private final List<RequestMatcher> requestMatchers;
private final List<? extends RequestMatcher> requestMatchers;
/**
* Creates a new instance
* @param requestMatchers the {@link RequestMatcher} instances to try
*/
public OrRequestMatcher(List<RequestMatcher> requestMatchers) {
public OrRequestMatcher(List<? extends RequestMatcher> requestMatchers) {
Assert.notEmpty(requestMatchers, "requestMatchers must contain a value");
Assert.noNullElements(requestMatchers, "requestMatchers cannot contain null values");
this.requestMatchers = requestMatchers;