-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
UNC path rejected for @QuarkusTest #31368
Comments
Thanks for the analysis! Would you to provide a Pull Request? |
ATM I lack time for setting up an environment. I'll get back to this as soon as possible. |
👌🏼 |
@dmlloyd @aloubyansky does this solution seem liike the best way to go to you? I admit I have never worked with UNC Paths and I was not able to find any definiteve information... |
Yes, I think this is an OK fix. It's a bit weird that the URL->URI conversion is not reliable, but this is definitely the cleanest way around at (assuming it works). |
Thanks @dmlloyd |
Interesting enough, the change above makes one of our tests fail:
The even weirder thing is that
is true. |
What is giving the error? |
The stacktrace is: [ERROR] io.quarkus.deployment.pkg.steps.BannerProcessorTest.checkQuarkusCoreBannerOnFilesystemWithSpecialCharacters(Path) Time elapsed: 0.046 s <<< ERROR!
java.lang.IllegalArgumentException: Bad escape
at java.base/sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:88)
at java.base/sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:102)
at java.base/java.nio.file.Path.of(Path.java:203)
at java.base/java.nio.file.Paths.get(Paths.java:98)
at io.quarkus.runtime.util.ClassPathUtils.toLocalPath(ClassPathUtils.java:228)
at io.quarkus.runtime.util.ClassPathUtils.processAsPath(ClassPathUtils.java:144)
at io.quarkus.deployment.steps.BannerProcessor.isQuarkusCoreBanner(BannerProcessor.java:112)
at io.quarkus.deployment.pkg.steps.BannerProcessorTest$MyBannerProcessor.test(BannerProcessorTest.java:21)
at io.quarkus.deployment.pkg.steps.BannerProcessorTest.checkQuarkusCoreBannerOnFilesystemWithSpecialCharacters(BannerProcessorTest.java:39) The URL being passed in is something like: However I see that the test takes a
down the line. I assume something is getting lost in translation? |
Working backwards, I can see that Taking this farther, consider the following cases for
OK, so now we know that
I'd look at these places to see where the escapes get lost. |
Right, that's what I saw with quick debugging as well.
Thanks a ton for the hints @dmlloyd! |
I am looking at this a little more and it seems like the problem is actually not encoding related (or at least, not only encoding related. For the test we are talking about, the difference between Paths.get(url.toURI()) and Paths.get(new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), url.getRef())) boils down to the former's (as the JDK does: and that is why it passes. |
I can get path this particular error in the test by ASCII encoding the URI, but then we run into another problem that the ZipFileSystem won't open because it supposedly does not exist. At this point I think I'm just gonna give up |
I am going to close this as it will be hard to fix for very very little gain |
This might be fixed as a side-effect of #42248. |
Describe the bug
Setup:
//wsl2/Ubuntu 20.04/projects/myproject
network share in Windows.When I run a test file from Eclipse (Run > Run JUnit test)
Expected behavior
the test case should run under windows.
Actual behavior
The test case outputs an error and throws an exception:
BasicLoggingEnabler failed to retrieve config: java.lang.IllegalArgumentException: URI authority component has undefined host
How to Reproduce?
-Djava.util.logging.manager=org.jboss.logmanager.LogManager -Dmaven.home=<path-to-your-maven-installation>
, and mark as default JRE..project
file on the network share, otherwise Eclipse explodes.Output of
uname -a
orver
Microsoft Windows [Version 10.0.19045.2486]
Output of
java -version
openjdk version "17.0.5" 2022-10-18
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.14.3.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Additional information
Analysis
When
@QuarkusTest
loads a test class, it invokesPathTestHelper.getTestClassesLocation(Class<?> testClass)
.The utility method correctly determines the full URL to the test class, e.g.
i.e. the authority component is empty (correct), the path component starts with a double slash (correct).
Then, on line 146, it invokes
The
toPath
function fails when it invokesClassPathUtils.toLocalPath
which usesto convert the correct URL into an incorrect URI whose authority part is
wsl2
and whose path is/Ubuntu 20.04/projects/myproject/src/test/java/my/test/project/TestTestcase.class
As file URLs must not have an authority part, the URI is rejected by
java.nio.file.Path.get
.Suggested Solution
Instead of using
toURI
inClassPathUtils.toLocalPath
, the URI should be constructed directly.In this case, the path is fully preserved, and the failure checks remain in place if the URL erroneously contained an authority part.
The text was updated successfully, but these errors were encountered: