Skip to content

Commit babd551

Browse files
committed
Revert ParsingPathMatcher concurrency checks
`PathPatternParser` is now thread-safe and creates a new internal parser for each `parse` call, since this operation is cheap. This commit removes the `ThreadLocal` based instances of `PathPatternParser` in `ParsingPathMatcher` which are not required anymore. Issue: SPR-15246
1 parent a0505bf commit babd551

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

spring-web/src/main/java/org/springframework/web/util/ParsingPathMatcher.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public class ParsingPathMatcher implements PathMatcher {
4343
private final ConcurrentMap<String, PathPattern> cache =
4444
new ConcurrentHashMap<>(64);
4545

46-
private static final ThreadLocal<PathPatternParser> PARSER
47-
= ThreadLocal.withInitial(() -> new PathPatternParser());
46+
private final PathPatternParser parser = new PathPatternParser();
4847

4948
@Override
5049
public boolean match(String pattern, String path) {
@@ -113,7 +112,7 @@ public boolean isPattern(String path) {
113112
private PathPattern getPathPattern(String pattern) {
114113
PathPattern pathPattern = this.cache.get(pattern);
115114
if (pathPattern == null) {
116-
pathPattern = PARSER.get().parse(pattern);
115+
pathPattern = this.parser.parse(pattern);
117116
this.cache.put(pattern, pathPattern);
118117
}
119118
return pathPattern;

spring-web/src/main/java/org/springframework/web/util/patterns/PathPatternParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public void setCaseSensitive(boolean caseSensitive) {
6363
* @param pathPattern the input path pattern, e.g. /foo/{bar}
6464
* @return a PathPattern for quickly matching paths against the specified path pattern
6565
*/
66-
public PathPattern parse(String pattern) {
66+
public PathPattern parse(String pathPattern) {
6767
InternalPathPatternParser ippp = new InternalPathPatternParser(separator, caseSensitive);
68-
return ippp.parse(pattern);
68+
return ippp.parse(pathPattern);
6969
}
7070

7171
}

0 commit comments

Comments
 (0)