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 fails to resolve resources from JAR located in path with '#' on JDK 11+ #26104

Closed
rweisleder opened this issue Nov 17, 2020 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@rweisleder
Copy link
Contributor

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 17, 2020
@jhoeller jhoeller self-assigned this Nov 17, 2020
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 17, 2020
@jhoeller jhoeller added this to the 5.3.2 milestone Nov 17, 2020
@jhoeller jhoeller added the for: backport-to-5.2.x Marks an issue as a candidate for backport to 5.2.x label Nov 17, 2020
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.2.x Marks an issue as a candidate for backport to 5.2.x labels Nov 17, 2020
@jhoeller jhoeller added the for: backport-to-5.1.x Marks an issue as a candidate for backport to 5.1.x label Nov 17, 2020
@spring-projects-issues spring-projects-issues removed the for: backport-to-5.1.x Marks an issue as a candidate for backport to 5.1.x label Nov 17, 2020
@jhoeller jhoeller changed the title PathMatchingResourcePatternResolver fails to resolve resources from JAR located in path with '#' PathMatchingResourcePatternResolver fails to resolve resources from JAR located in path with '#' on JDK 11+ Nov 17, 2020
@jhoeller
Copy link
Contributor

jhoeller commented Nov 17, 2020

@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).

@rweisleder
Copy link
Contributor Author

It worked for me with spring-core-5.3.2-20201118.144452-29.jar
Thanks for the quick response and fix!

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) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants