@@ -55,7 +55,7 @@ public final class PathPatternRequestMatcher implements RequestMatcher {
5555
5656 private final PathPattern pattern ;
5757
58- private RequestMatcher method = AnyRequestMatcher . INSTANCE ;
58+ private final RequestMatcher method ;
5959
6060 /**
6161 * Creates a {@link PathPatternRequestMatcher} that uses the provided {@code pattern}.
@@ -64,8 +64,9 @@ public final class PathPatternRequestMatcher implements RequestMatcher {
6464 * </p>
6565 * @param pattern the pattern used to match
6666 */
67- private PathPatternRequestMatcher (PathPattern pattern ) {
67+ private PathPatternRequestMatcher (PathPattern pattern , RequestMatcher method ) {
6868 this .pattern = pattern ;
69+ this .method = method ;
6970 }
7071
7172 /**
@@ -142,10 +143,6 @@ public MatchResult matcher(HttpServletRequest request) {
142143 return (info != null ) ? MatchResult .match (info .getUriVariables ()) : MatchResult .notMatch ();
143144 }
144145
145- void setMethod (RequestMatcher method ) {
146- this .method = method ;
147- }
148-
149146 private PathContainer getPathContainer (HttpServletRequest request ) {
150147 RequestPath path ;
151148 if (ServletRequestPathUtils .hasParsedRequestPath (request )) {
@@ -320,11 +317,8 @@ public PathPatternRequestMatcher matcher(@Nullable HttpMethod method, String pat
320317 Assert .notNull (path , "pattern cannot be null" );
321318 Assert .isTrue (path .startsWith ("/" ), "pattern must start with a /" );
322319 PathPattern pathPattern = this .parser .parse (this .basePath + path );
323- PathPatternRequestMatcher requestMatcher = new PathPatternRequestMatcher (pathPattern );
324- if (method != null ) {
325- requestMatcher .setMethod (new HttpMethodRequestMatcher (method ));
326- }
327- return requestMatcher ;
320+ return new PathPatternRequestMatcher (pathPattern ,
321+ (method != null ) ? new HttpMethodRequestMatcher (method ) : AnyRequestMatcher .INSTANCE );
328322 }
329323
330324 }
0 commit comments