Merge branch '5.2.x'

This commit is contained in:
Rossen Stoyanchev
2020-06-03 06:14:20 +01:00
10 changed files with 77 additions and 34 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,8 +40,6 @@ import org.springframework.web.util.pattern.PathPatternParser;
*/
class PathResourceLookupFunction implements Function<ServerRequest, Optional<Resource>> {
private static final PathPatternParser PATTERN_PARSER = new PathPatternParser();
private final PathPattern pattern;
private final Resource location;
@@ -50,7 +48,7 @@ class PathResourceLookupFunction implements Function<ServerRequest, Optional<Res
public PathResourceLookupFunction(String pattern, Resource location) {
Assert.hasLength(pattern, "'pattern' must not be empty");
Assert.notNull(location, "'location' must not be null");
this.pattern = PATTERN_PARSER.parse(pattern);
this.pattern = PathPatternParser.defaultInstance.parse(pattern);
this.location = location;
}

View File

@@ -72,9 +72,6 @@ public abstract class RequestPredicates {
private static final Log logger = LogFactory.getLog(RequestPredicates.class);
private static final PathPatternParser DEFAULT_PATTERN_PARSER = new PathPatternParser();
/**
* Return a {@code RequestPredicate} that always matches.
* @return a predicate that always matches
@@ -114,7 +111,7 @@ public abstract class RequestPredicates {
if (!pattern.isEmpty() && !pattern.startsWith("/")) {
pattern = "/" + pattern;
}
return pathPredicates(DEFAULT_PATTERN_PARSER).apply(pattern);
return pathPredicates(PathPatternParser.defaultInstance).apply(pattern);
}
/**

View File

@@ -72,7 +72,6 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
private static final RequestConditionHolder EMPTY_CUSTOM = new RequestConditionHolder(null);
@Nullable
private final String name;
@@ -90,6 +89,8 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
private final RequestConditionHolder customConditionHolder;
private final int hashCode;
public RequestMappingInfo(@Nullable String name, @Nullable PatternsRequestCondition patterns,
@Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params,
@@ -104,6 +105,10 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
this.consumesCondition = (consumes != null ? consumes : EMPTY_CONSUMES);
this.producesCondition = (produces != null ? produces : EMPTY_PRODUCES);
this.customConditionHolder = (custom != null ? new RequestConditionHolder(custom) : EMPTY_CUSTOM);
this.hashCode = calculateHashCode(
this.patternsCondition, this.methodsCondition, this.paramsCondition, this.headersCondition,
this.consumesCondition, this.producesCondition, this.customConditionHolder);
}
/**
@@ -125,7 +130,6 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
info.consumesCondition, info.producesCondition, customRequestCondition);
}
/**
* Return the name for this mapping, or {@code null}.
*/
@@ -336,10 +340,17 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
@Override
public int hashCode() {
return (this.patternsCondition.hashCode() * 31 + // primary differentiation
this.methodsCondition.hashCode() + this.paramsCondition.hashCode() +
this.headersCondition.hashCode() + this.consumesCondition.hashCode() +
this.producesCondition.hashCode() + this.customConditionHolder.hashCode());
return this.hashCode;
}
private static int calculateHashCode(
PatternsRequestCondition patterns, RequestMethodsRequestCondition methods,
ParamsRequestCondition params, HeadersRequestCondition headers,
ConsumesRequestCondition consumes, ProducesRequestCondition produces,
RequestConditionHolder custom) {
return patterns.hashCode() * 31 + methods.hashCode() + params.hashCode() +
headers.hashCode() + consumes.hashCode() + produces.hashCode() + custom.hashCode();
}
@Override