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
Spring PathMatchingResourcePatternResolver does not return the subdirectory of a URL resource. #10943
Comments
/cc @geoand |
I am unsure if this problem is a SpringFramework, a Quarkus or perhaps in the combination of the two. |
I would need to look into the source of that specific Spring class to see what it does, but in general this is not one of the classes we support / test. One more question, in what mode does this happen? When running the application via |
This problem happens when doing:
It finds It works as intended when doing:
It finds Notable difference is that in the first two the jar file is loaded from the local maven repository. In the last case it is loaded from the target/lib of the project that is built. |
I'll take a look, it might be some subtle misbehavior of the Quarkus Classloader |
@stuartwdouglas it seems like the Quarkus ClassLoader behaves differently than the URLClassLoader on Do you remember why I am not really worried about |
I updated my reproduction project: I move the resources one directory level deeper. Now the Java test shows Which contains the correct /Content/deeper/world.txt The Quarkus variant shows
Which contains the incorrect /deeper/world.txt So apparently the first directory level is stripped. |
Pretty much yeah |
URLClassLoader will add a trailing / to the URL if the passed in name contains a /. This makes our behaviour mirror this. It also adds a check that if the name ends with a / we only return directory entries. Fixes quarkusio#10943
@geoand it looks like at some point we added this explicitly for file system directories: 4e58a7d (although the message for that commit seems to be the opposite to what the commit actually does). I checked UrlClassLoader and the presence or absence of a '/' seems to depend on what is passed in, if the resource name has a trailing slash then it will be present, otherwise it won't. I have opened a PR to attempt to duplicate this behaviour. |
URLClassLoader will add a trailing / to the URL if the passed in name contains a /. This makes our behaviour mirror this. It also adds a check that if the name ends with a / we only return directory entries. Fixes quarkusio#10943
Thanks @stuartwdouglas |
I'm wondering if a dev mode test should be added based on the reproducer from this issue. My thinking is that if we are testing the use of |
I have opened #11009 that adds a test around the URL behaviour. |
Excellent, thanks |
Describe the bug
I use
org.springframework.core.io.support.PathMatchingResourcePatternResolver
to find resources packaged inside a jar which are in a subdirectory.When I do this in a normal Java application the resource that is found correctly looks like this:
yet when I run the exact same code in a Quarkus application it finds the file yet the returned resource does not have the subdirectory of the file.
So the difference is that in the Quarkus setup the resource is not reported in the actual subdirectory it is really stored in.
Thus: loading the resource will fail with a file not found.
Expected behavior
The located resources are found in the correct place.
Actual behavior
The subdirectory name is missing in the path of the found resources.
To Reproduce
https://github.com/nielsbasjes/BugReport-SpringQuarkus-ResourceLoading
Environment (please complete the following information):
uname -a
orver
:Linux lw7-06766 4.4.0-185-generic #215-Ubuntu SMP Mon Jun 8 21:53:19 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
java -version
:openjdk version "1.8.0_252" OpenJDK Runtime Environment (build 1.8.0_252-b09) OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (build 25.252-b09-jvmci-20.1-b02, mixed mode)
1.6.1.Final
mvnw --version
orgradlew --version
):Apache Maven 3.6.2
Additional context
This was reported as a bug in the library I have written: nielsbasjes/yauaa#216
The text was updated successfully, but these errors were encountered: