-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
PathMatchingResourcePatternResolver incorrectly rejects absolute paths in JAR manifest Class-Path entries, causing classpath scanning to fail with patterns like classpath*:**/*.class.
Minimal reproduction: https://github.com/Artur-/spring-manifest-bug-demo
git clone https://github.com/Artur-/spring-manifest-bug-demo.git
cd spring-manifest-bug-demo
mvn dependency:resolve
./create-classpath-jar.sh
./run-test.shResult:
- classpath*:**/*.class → 2 classes ❌ (missing dependencies)
- classpath*:org/**/*.class → 458 classes ✓ (works correctly)
Root Cause
File: PathMatchingResourcePatternResolver.java:615
File candidate = new File(parent, path);
if (candidate.isFile() && candidate.getCanonicalPath().contains(parent.getCanonicalPath())) {
manifestEntries.add(ClassPathManifestEntry.of(candidate));
}The security check rejects JARs that aren't within the parent directory. However, when Gradle creates a classpath JAR on Windows (to avoid the ~8KB command-line limit), it uses absolute paths to dependency JARs in the user's .gradle/caches/ directory. These are legitimate dependencies, not files that should be restricted to the parent directory.
Example of valid manifest created by Gradle:
Classpath JAR location: C:/project/build/tmp/bootRun/classpath.jar
Manifest Class-Path: C:/Users/developer/.gradle/caches/modules-2/files-2.1/.../spring-core-6.2.1.jar
The code extracts:
parent = "C:/project/build/tmp/bootRun/" (parent of classpath.jar)
path = "C:/Users/developer/.gradle/caches/.../spring-core-6.2.1.jar" (from manifest)
The check fails because the Gradle cache path doesn't contain the bootRun directory path, but these are valid dependency JARs that should be loaded.
When This Occurs
- Windows with Gradle (classpath exceeds ~8KB limit)
- IntelliJ IDEA with classpath shortening
- Any build tool using absolute paths in manifest Class-Path
Related Issues
- PathMatchingResourcePatternResolver does not consider manifest based classpaths [SPR-13685] #18260,
PathMatchingResourcePatternResolvergives different results with classpath in JAR manifest #28276, PathMatchingResourcePatternResolver does not always work with JAR manifest class paths #24480 - Development mode not working due to long classpath. vaadin/flow#21051