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

Fix File resolver when classloader provides URLs for directories #5092

Merged

Conversation

cescoffier
Copy link
Contributor

@cescoffier cescoffier commented Feb 3, 2024

Handle the case where the file resolver is used with a classloader that returns a URL for directories.

When unpackFromJarURL is called with a directory, the method throws an exception as the entry does not exist. We can detect the case by checking the length and not trying to retrieve the JarFile from the connection.

@cescoffier cescoffier changed the base branch from master to 4.x February 3, 2024 17:50
@cescoffier cescoffier requested a review from vietj February 3, 2024 17:50
@vietj
Copy link
Member

vietj commented Feb 4, 2024

can we test this ? what's the reproducer ?

@vietj vietj added this to the 4.5.3 milestone Feb 4, 2024
@cescoffier
Copy link
Contributor Author

I have been trying to add a test but it's not that simple. Even when creating my own resolver I'm not able to reproduce.

However, since the introduction of Vert.x 4.5, we got multiple reports that webjars and mvnpm jars cannot be loaded anymore. It brokes lot of existing applications.

Here is one of the exception we have seen:

2024-02-02 15:19:28,058 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (vert.x-eventloop-thread-3) HTTP Request to /_static/wc-chatbot/0.1.2/dist/wc-chatbot.js failed, error id: 24aae10e-d749-4380-b81b-79714ed67f28-1: io.vertx.core.VertxException: Unable to unpack file at path 'jar:file:///Users/clement/.m2/repository/org/mvnpm/wc-chatbot/0.1.2/wc-chatbot-0.1.2.jar!/META-INF/resources/_static/wc-chatbot/0.1.2/dist'
at io.vertx.core.file.impl.FileResolverImpl.unpackFromJarURL(FileResolverImpl.java:360)
at io.vertx.core.file.impl.FileResolverImpl.unpackUrlResource(FileResolverImpl.java:247)
at io.vertx.core.file.impl.FileResolverImpl.resolveFile(FileResolverImpl.java:170)
at io.vertx.core.impl.VertxImpl.resolveFile(VertxImpl.java:929)
at io.vertx.core.file.impl.FileSystemImpl$20.perform(FileSystemImpl.java:1135)
at io.vertx.core.file.impl.FileSystemImpl$20.perform(FileSystemImpl.java:1133)
at io.vertx.core.file.impl.FileSystemImpl$BlockingAction.handle(FileSystemImpl.java:1174)
at io.vertx.core.file.impl.FileSystemImpl$BlockingAction.handle(FileSystemImpl.java:1156)
at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$1(ContextImpl.java:190)
at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:276)
at io.vertx.core.impl.ContextImpl.lambda$internalExecuteBlocking$2(ContextImpl.java:209)
at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.io.FileNotFoundException: JAR entry META-INF/resources/_static/wc-chatbot/0.1.2/dist not found in /Users/clement/.m2/repository/org/mvnpm/wc-chatbot/0.1.2/wc-chatbot-0.1.2.jar
at java.base/sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:146)
at java.base/sun.net.www.protocol.jar.JarURLConnection.getJarFile(JarURLConnection.java:92)
at io.vertx.core.file.impl.FileResolverImpl.unpackFromJarURL(FileResolverImpl.java:320)
... 18 more

Something that puzzled me is that these "jars" do not have a MANIFEST, they are just zips.

…at return a URL for directories.

When unpackFromJarURL is called with a directory, the method throws an exception as the entry does not really exist. By checking the length we can detect the case and not try to retrieve the JarFile from the connection.
@cescoffier cescoffier force-pushed the fix-file-resolver-when-reading-dir branch from 088d631 to c93703e Compare February 5, 2024 13:53
@cescoffier cescoffier changed the title Fix File resolution when the first attempt is a directory Fix File resolver when classloader provides URLs for directories Feb 5, 2024
@cescoffier
Copy link
Contributor Author

@vietj with a test case :-D

@vietj vietj merged commit 0eeba1a into eclipse-vertx:4.x Feb 5, 2024
7 checks passed
@vietj
Copy link
Member

vietj commented Feb 5, 2024

thanks @cescoffier can you port to master branch as well ?

@vietj vietj added the bug label Feb 5, 2024
@cescoffier
Copy link
Contributor Author

Sure! Let me do that right away!

@cescoffier
Copy link
Contributor Author

Port to master: #5093

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants