Polishing contribution
Closes gh-29634
This commit is contained in:
@@ -170,8 +170,11 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
|
||||
protected HandlerMethod handleNoMatch(Set<RequestMappingInfo> infos,
|
||||
ServerWebExchange exchange) throws Exception {
|
||||
|
||||
PartialMatchHelper helper = PartialMatchHelper.from(infos, exchange);
|
||||
if (CollectionUtils.isEmpty(infos)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PartialMatchHelper helper = new PartialMatchHelper(infos, exchange);
|
||||
if (helper.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -222,12 +225,10 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
|
||||
*/
|
||||
private static final class PartialMatchHelper {
|
||||
|
||||
private static final PartialMatchHelper EMPTY_HELPER = new PartialMatchHelper(Collections.emptySet(), null);
|
||||
|
||||
private final List<PartialMatch> partialMatches = new ArrayList<>();
|
||||
|
||||
|
||||
private PartialMatchHelper(Set<RequestMappingInfo> infos, ServerWebExchange exchange) {
|
||||
PartialMatchHelper(Set<RequestMappingInfo> infos, ServerWebExchange exchange) {
|
||||
for (RequestMappingInfo info : infos) {
|
||||
if (info.getPatternsCondition().getMatchingCondition(exchange) != null) {
|
||||
this.partialMatches.add(new PartialMatch(info, exchange));
|
||||
@@ -235,13 +236,6 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
|
||||
}
|
||||
}
|
||||
|
||||
public static PartialMatchHelper from(Set<RequestMappingInfo> infos, ServerWebExchange exchange) {
|
||||
if (CollectionUtils.isEmpty(infos)) {
|
||||
return EMPTY_HELPER;
|
||||
}
|
||||
return new PartialMatchHelper(infos, exchange);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether there are any partial matches.
|
||||
*/
|
||||
|
||||
@@ -346,9 +346,9 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleNoMatchEmptyRequestMappingInfo() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(post("/bar"));
|
||||
@Test // gh-29611
|
||||
public void handleNoMatchWithoutPartialMatches() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(post("/non-existent"));
|
||||
|
||||
HandlerMethod handlerMethod = this.handlerMapping.handleNoMatch(new HashSet<>(), exchange);
|
||||
assertThat(handlerMethod).isNull();
|
||||
|
||||
Reference in New Issue
Block a user