Skip to content

PathMatchingResourcePatternResolver fails to resolve resources from JAR located in path with '#' on JDK 11+ #26104

@rweisleder

Description

@rweisleder

Affects: Spring Framework 5.3.1 on JRE 11+


I have a simple JAR which contains the resource demo/dummy.txt and a class with this code:

ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources("classpath*:**/dummy.txt");
System.out.println("resources = " + Arrays.toString(resources));

If I put this JAR into c:\tmp\demo and run the code, the resource is found.
If I put this JAR into c:\tmp\#demo and run the code, no resources are found. Instead, an exception is logged at debug level:

Cannot search for matching files underneath [c:\tmp\#demo\resource-resolver-demo-1.0-SNAPSHOT.jar] because it cannot be converted to a valid 'jar:' URL: no !/ in spec

java.net.MalformedURLException: no !/ in spec
	at java.base/java.net.URL.<init>(URL.java:679)
	at java.base/java.net.URL.<init>(URL.java:541)
	at java.base/java.net.URL.<init>(URL.java:488)
	at org.springframework.core.io.UrlResource.<init>(UrlResource.java:95)
	at org.springframework.core.io.support.PathMatchingResourcePatternResolver.addClassPathManifestEntries(PathMatchingResourcePatternResolver.java:435)
	at org.springframework.core.io.support.PathMatchingResourcePatternResolver.addAllClassLoaderJarRoots(PathMatchingResourcePatternResolver.java:400)
	at org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindAllClassPathResources(PathMatchingResourcePatternResolver.java:346)
	at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findAllClassPathResources(PathMatchingResourcePatternResolver.java:321)
	at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:288)
	at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:494)
	at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:284)
	at demo.ResourceResolverDemo.main(ResourceResolverDemo.java:13)
Caused by: java.lang.NullPointerException: no !/ in spec
	at java.base/sun.net.www.protocol.jar.Handler.parseAbsoluteSpec(Handler.java:181)
	at java.base/sun.net.www.protocol.jar.Handler.parseURL(Handler.java:163)
	at java.base/java.net.URL.<init>(URL.java:674)
	... 11 more

This is only reproducible with JRE 11 and newer. Both cases work as expected if I run them with JRE 8.

See also this demo project: https://github.com/rweisleder/resource-resolver-demo

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions