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
Comment From: jhoeller
@rweisleder, I've just committed a revision that encodes the hash symbol in addClassPathManifestEntries
, verified with some local tests. Please give the latest 5.3.2 snapshot (https://repo.spring.io/snapshot/org/springframework/spring-framework-bom/) a try and let me know whether this works in your scenario as well... I'll backport it to 5.2.12 and 5.1.20 then (where we aim for JDK 11 compatibility as well).
Comment From: rweisleder
It worked for me with spring-core-5.3.2-20201118.144452-29.jar Thanks for the quick response and fix!