Ignore entries cache if no matching root entry path found

Closes gh-34446
This commit is contained in:
Juergen Hoeller
2025-02-23 14:02:57 +01:00
parent 5a0bd9e5d4
commit 725b02a66d

View File

@@ -816,17 +816,21 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
// Clean root entry path to match jar entries format without "!" separators
rootEntryPath = rootEntryPath.replace(ResourceUtils.JAR_URL_SEPARATOR, "/");
// Search sorted entries from first entry with rootEntryPath prefix
boolean rootEntryPathFound = false;
for (String entryPath : entriesCache.tailSet(rootEntryPath, false)) {
if (!entryPath.startsWith(rootEntryPath)) {
// We are beyond the potential matches in the current TreeSet.
break;
}
rootEntryPathFound = true;
String relativePath = entryPath.substring(rootEntryPath.length());
if (getPathMatcher().match(subPattern, relativePath)) {
result.add(rootDirResource.createRelative(relativePath));
}
}
return result;
if (rootEntryPathFound) {
return result;
}
}
}