diff --git a/spring-core/src/main/java/org/springframework/core/ResolvableType.java b/spring-core/src/main/java/org/springframework/core/ResolvableType.java index 16cd8c4792b84c95bacd88879c3e0186d5706039..78c7e88f3063d2c5f5054e26521f355aea7fdba0 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableType.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableType.java @@ -1192,12 +1192,17 @@ public final class ResolvableType implements Serializable { if (type == null) { return NONE; } - // Check the cache, we may have a ResolvableType that may have already been resolved + + // Purge empty entries on access since we don't have a clean-up thread or the like. cache.purgeUnreferencedEntries(); + // For simple Class references, build the wrapper right away - + // no expensive resolution necessary, so not worth caching... if (type instanceof Class) { return new ResolvableType(type, typeProvider, variableResolver, null); } + + // Check the cache - we may have a ResolvableType which has been resolved before... ResolvableType key = new ResolvableType(type, typeProvider, variableResolver); ResolvableType resolvableType = cache.get(key); if (resolvableType == null) { diff --git a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java index 1253ec8d1f79faefd54cafbd1358847b9f8954b7..ff2056ab6280584d2957278c09b3db2d6b76ecd4 100644 --- a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java @@ -58,7 +58,9 @@ public class AntPathMatcher implements PathMatcher { private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{[^/]+?\\}"); - private String pathSeparator = DEFAULT_PATH_SEPARATOR; + private String pathSeparator; + + private PathSeparatorPatternCache pathSeparatorPatternCache; private boolean trimTokens = true; @@ -68,13 +70,13 @@ public class AntPathMatcher implements PathMatcher { final Map stringMatcherCache = new ConcurrentHashMap(256); - private PathSeparatorPatternCache pathSeparatorPatternCache = new PathSeparatorPatternCache(DEFAULT_PATH_SEPARATOR); - /** * Create a new instance with the {@link #DEFAULT_PATH_SEPARATOR}. */ public AntPathMatcher() { + this.pathSeparator = DEFAULT_PATH_SEPARATOR; + this.pathSeparatorPatternCache = new PathSeparatorPatternCache(DEFAULT_PATH_SEPARATOR); } /** @@ -580,14 +582,13 @@ public class AntPathMatcher implements PathMatcher { * {@link #getPatternComparator(String)}. *

In order, the most "generic" pattern is determined by the following: *

- *

*/ protected static class AntPatternComparator implements Comparator { @@ -598,15 +599,13 @@ public class AntPathMatcher implements PathMatcher { } /** - * Compare two patterns to determine which should match first, i.e. which is the most specific - * regarding the current path. - * + * Compare two patterns to determine which should match first, i.e. which + * is the most specific regarding the current path. * @return a negative integer, zero, or a positive integer as pattern1 is * more specific, equally specific, or less specific than pattern2. */ @Override public int compare(String pattern1, String pattern2) { - PatternInfo info1 = new PatternInfo(pattern1); PatternInfo info2 = new PatternInfo(pattern2); @@ -664,6 +663,7 @@ public class AntPathMatcher implements PathMatcher { return 0; } + /** * Value class that holds information about the pattern, e.g. number of * occurrences of "*", "**", and "{" pattern elements. @@ -684,7 +684,6 @@ public class AntPathMatcher implements PathMatcher { private Integer length; - public PatternInfo(String pattern) { this.pattern = pattern; if (this.pattern != null) { @@ -769,8 +768,7 @@ public class AntPathMatcher implements PathMatcher { private final String endsOnDoubleWildCard; - - private PathSeparatorPatternCache(String pathSeparator) { + public PathSeparatorPatternCache(String pathSeparator) { this.endsOnWildCard = pathSeparator + "*"; this.endsOnDoubleWildCard = pathSeparator + "**"; }