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 Quarkus ClassLoader's jar ProtectionDomain handling #11970

Merged
merged 1 commit into from
Sep 8, 2020

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Sep 8, 2020

Bring it inline with what URLClassLoader does

Fixes: #11549

@geoand
Copy link
Contributor Author

geoand commented Sep 8, 2020

@stuartwdouglas I assume that the current code was just the result of a bug? Or did you have something specific in mind?

@geoand
Copy link
Contributor Author

geoand commented Sep 8, 2020

The CI is due to this PR - looking at it now

@geoand
Copy link
Contributor Author

geoand commented Sep 8, 2020

CI issue should now be fixed - Pinging @jaikiran as well since I made a change to his code

@jaikiran
Copy link
Member

jaikiran commented Sep 8, 2020

I'm a bit surprised that it's failing in JRE, because from what I can tell, I don't think the current code in JarClassPathElement is doing anything incorrect. Let me see if I can reproduce this standalone outside of Quarkus.

@geoand
Copy link
Contributor Author

geoand commented Sep 8, 2020

@jaikiran #11549 (comment) (which I was able to reproduce) was the reason I made this change

@jaikiran
Copy link
Member

jaikiran commented Sep 8, 2020

I could reproduce this outside of Quarkus in a simple Java class. So I asked for inputs from the JDK team[1]. The initial assessment is that, the construct used by Kotlin(?) and that other library in the linked issue:

new JarInputStream(kotlinUnit.getProtectionDomain().getCodeSource().getLocation().openStream())

isn't expected to work when the URL in question is a jar:file URL.

So I went ahead and tried out simple test to see how URLClassLoader behaves when it comes to CodeSource location and what URL it returns for classes loaded out of jar files in the classpath. My tests show that it matches with your changes and it returns a plain file: URL (example file:/tmp/some-jar.jar).

So this change looks fine to me.

[1] https://mail.openjdk.java.net/pipermail/net-dev/2020-September/014389.html

@geoand
Copy link
Contributor Author

geoand commented Sep 8, 2020

Awesome, thanks for the great analysis @jaikiran!

@@ -217,7 +218,8 @@ void registerExchangeAttributeBuilders(final BuildProducer<ServiceProviderBuildI
logger.debug("Skipping registration of service providers for " + ExchangeAttributeBuilder.class);
return;
}
try (final FileSystem jarFileSystem = ZipUtils.newFileSystem(codeSource.getLocation().toURI(),
try (final FileSystem jarFileSystem = ZipUtils.newFileSystem(
new URI("jar", codeSource.getLocation().toURI().toString(), null),
Copy link
Member

@jaikiran jaikiran Sep 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These URI/URL APIs are sometimes a bit too complex and I usually have to go back read their docs multiple times and even try out a few things to be sure that whatever construct is being used/changed will work fine without issues. So, I'm unsure if this change will cause any issues. However, given that this specific area of code has relevant tests[1] that cover Java 8, 11, 14 and even native-image, we can go ahead with this change if the CI shows all green.

[1] #9474

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed :)

@geoand
Copy link
Contributor Author

geoand commented Sep 8, 2020

CI failure seems totally unrelated, but since this change could potentially have a wide impact, I will restart CI since I want to be totally sure

@gsmet
Copy link
Member

gsmet commented Sep 8, 2020

@stuartwdouglas I let you check this one? I will backport it tomorrow morning.

@stuartwdouglas stuartwdouglas merged commit 604a84a into quarkusio:master Sep 8, 2020
@geoand geoand deleted the #11549 branch September 9, 2020 05:14
@geoand geoand modified the milestone: 1.8.0.Final Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quarkus, Jackson and Kotlin 1.4
4 participants