Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PathMatchingResourcePatternResolver throws FileNotFoundException caused by wrong cache path #34111

Open
fangzhengjin opened this issue Dec 18, 2024 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@fangzhengjin
Copy link

  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;
		}
	}
}
@fangzhengjin

This comment was marked as abuse.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 18, 2024
@jhoeller jhoeller added type: regression A bug that is also a regression in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 18, 2024
@jhoeller jhoeller self-assigned this Dec 18, 2024
@jhoeller jhoeller added this to the 6.2.2 milestone Dec 18, 2024
@snicoll snicoll changed the title [BUG] PathMatchingResourcePatternResolver FileNotFoundException caused by wrong cache path PathMatchingResourcePatternResolver throws FileNotFoundException caused by wrong cache path Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

3 participants