Skip to content

PathMatchingResourcePatternResolver is not able to resolve file in SpringBoot Packaged JARΒ #34126

@pawank94

Description

@pawank94

This issue is happening for Spring Boot generated JAR file
When resolving for a path in JAR file jar:file:~/Documents/_GIT/xxxxx/example.jar!/BOOT-INF/classes!/com/xxxx in PathMatchingResourcePatternResolver. . The changes done in this commit seem to cause an issue.

Old Code:

for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements(); ) {
				JarEntry entry = entries.nextElement();
				String entryPath = entry.getName();
				entryCache.add(entryPath);
				if (entryPath.startsWith(rootEntryPath)) {

New Code

for (String entryPath : jarFile.stream().map(JarEntry::getName).sorted().toList()) {
				entriesCache.add(entryPath);
				if (entryPath.startsWith(rootEntryPath)) {

Upon analyzing, I noticed jarFile.entries() produces a different file path compared to jarFile.stream().map(JarEntry::getName). For the new code, the generated entryPath has the BOOT-INFO/ prefix added to it and the following .startsWith() check fails because of that.

This creates problems in resolving a resource in the Spring-Boot generated JAR File for New Code.

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