Skip to content

PathMatchingResourcePatternResolver throws FileNotFoundException caused by wrong cache pathΒ #34111

@fangzhengjin

Description

@fangzhengjin
  1. getResources("jar:file:/Users/xxxxx/.gradle/caches/modules-2/files-2.1/com.example1/example1/1.0.0/92cc99358ea6b25f5b9981c2a3f04e595705403f/example2-1.0.0.jar!/com/example1/")
  2. field rootDirCache will cache jar:file:/Users/xxxxx/.gradle/caches/modules-2/files-2.1/com.example1/example1/1.0.0/92cc99358ea6b25f5b9981c2a3f04e595705403f/example2-1.0.0.jar!/com/example1/
  3. getResources("jar:file:/Users/xxxxx/.gradle/caches/modules-2/files-2.1/com.example2/example2/1.0.0/92cc99358ea6b25f5b9981c2a3f04e595705403f/example2-1.0.0.jar!/com/example2/")
  4. field rootDirCache will remove existingPath and put new path jar:file:/Users/xxxxx/.gradle/caches/modules-2/files-2.1/ causes FileNotFoundException

Link: 19fec06#diff-69e11ca5877c77cb766565b03d43386f382f5321c62017d9e92f3615f6b3183eR605

Path judgment should be added to avoid caching invalid paths

Old

if (currentPrefix != null) {
	// A prefix match found, potentially to be turned into a common parent cache entry.
	if (commonPrefix == null || !commonUnique || currentPrefix.length() > commonPrefix.length()) {
		commonPrefix = currentPrefix;
		existingPath = path;
	}
	else if (currentPrefix.equals(commonPrefix)) {
		commonUnique = false;
	}
}

New

if (currentPrefix != null) {
	boolean startsWithJar = currentPrefix.startsWith("jar:");
	boolean containsJarExclamation = currentPrefix.contains(".jar!");
	if (startsWithJar && containsJarExclamation) {
		// A prefix match found, potentially to be turned into a common parent cache entry.
		if (commonPrefix == null || !commonUnique || currentPrefix.length() > commonPrefix.length()) {
			commonPrefix = currentPrefix;
			existingPath = path;
		}
		else if (currentPrefix.equals(commonPrefix)) {
			commonUnique = false;
		}
	}
}

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions