Skip to content

Use final values in equals and hashCode #17621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final class PathPatternRequestMatcher implements RequestMatcher {

private final PathPattern pattern;

private RequestMatcher method = AnyRequestMatcher.INSTANCE;
private final RequestMatcher method;

/**
* Creates a {@link PathPatternRequestMatcher} that uses the provided {@code pattern}.
Expand All @@ -64,8 +64,9 @@ public final class PathPatternRequestMatcher implements RequestMatcher {
* </p>
* @param pattern the pattern used to match
*/
private PathPatternRequestMatcher(PathPattern pattern) {
private PathPatternRequestMatcher(PathPattern pattern, RequestMatcher method) {
this.pattern = pattern;
this.method = method;
}

/**
Expand Down Expand Up @@ -108,10 +109,6 @@ public MatchResult matcher(HttpServletRequest request) {
return (info != null) ? MatchResult.match(info.getUriVariables()) : MatchResult.notMatch();
}

void setMethod(RequestMatcher method) {
this.method = method;
}

private PathContainer getPathContainer(HttpServletRequest request) {
RequestPath path;
if (ServletRequestPathUtils.hasParsedRequestPath(request)) {
Expand Down Expand Up @@ -286,11 +283,8 @@ public PathPatternRequestMatcher matcher(@Nullable HttpMethod method, String pat
Assert.notNull(path, "pattern cannot be null");
Assert.isTrue(path.startsWith("/"), "pattern must start with a /");
PathPattern pathPattern = this.parser.parse(this.basePath + path);
PathPatternRequestMatcher requestMatcher = new PathPatternRequestMatcher(pathPattern);
if (method != null) {
requestMatcher.setMethod(new HttpMethodRequestMatcher(method));
}
return requestMatcher;
return new PathPatternRequestMatcher(pathPattern,
(method != null) ? new HttpMethodRequestMatcher(method) : AnyRequestMatcher.INSTANCE);
}

}
Expand Down