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

ServiceLoader round-trips URL to URI and loses associated URLStreamHandler #16846

Closed
ulfjack opened this issue Apr 2, 2020 · 3 comments · Fixed by #16851
Closed

ServiceLoader round-trips URL to URI and loses associated URLStreamHandler #16846

ulfjack opened this issue Apr 2, 2020 · 3 comments · Fixed by #16851
Assignees
Labels
good first issue Good for newcomers Source: Community PR or issue was opened by a community user Team: Core Type: Defect
Milestone

Comments

@ulfjack
Copy link
Contributor

ulfjack commented Apr 2, 2020

I'm trying to load Hazelcast from a custom ClassLoader that is not backed by a file. Hazelcast calls ClassLoader.findResource to read the corresponding service descriptions from the .jar META-INF directory (like META-INF/services/com.hazelcast.instance.impl.NodeExtension). Unfortunately, the Hazelcast class com.hazelcast.internal.util.ServiceLoader first converts the URL to a URI, and then converts it back to a URI. If I return a URL with an associated URLStreamHandler, then that gets lost in the conversion process (because URI doesn't support it).

From the source code, it's not readily apparent why this is the case.

The only workaround seems to be to create a custom URLStreamHandlerFactory in the Jvm.

@mmedenjak mmedenjak added Team: Core Source: Community PR or issue was opened by a community user labels Apr 6, 2020
@mmedenjak
Copy link
Contributor

Seems this was introduced here by @sancar . Sancar, do you remember the reasoning?

@sancar
Copy link
Contributor

sancar commented Apr 6, 2020

Unfortunately I don't remember. From the heading of the pr, I assume that changes were accidental when trying to fix a checkstyle/findbugs issue.

@mmedenjak mmedenjak added the good first issue Good for newcomers label Apr 6, 2020
@mmedenjak
Copy link
Contributor

Thank you Sancar! @ulfjack care to send a PR?

@mmedenjak mmedenjak added this to the 4.1 milestone Apr 6, 2020
ulfjack added a commit to ulfjack/hazelcast that referenced this issue Apr 6, 2020
Instead, keep the original URL object returned from the ClassLoader. This
retains any associated URLStreamHandler with the URL, which allows the
ClassLoader to return in-memory resources.

As an alternative to this change, projects that want to use in-memory
resources with Hazelcast could replace the URLStreamHandlerFactory, adding a
custom scheme for in-memory resources. However, that seems a more invasive
approach, with this change being strictly simpler.

Fixes hazelcast#16846.
ulfjack added a commit to ulfjack/hazelcast that referenced this issue Apr 9, 2020
Instead, keep the original URL object returned from the ClassLoader. This
retains any associated URLStreamHandler with the URL, which allows the
ClassLoader to return in-memory resources.

As an alternative to this change, projects that want to use in-memory
resources with Hazelcast could replace the URLStreamHandlerFactory, adding a
custom scheme for in-memory resources. However, that seems a more invasive
approach, with this change being strictly simpler.

Fixes hazelcast#16846.
mmedenjak pushed a commit that referenced this issue Apr 14, 2020
Avoid round-tripping URLs through URI instances

Instead, keep the original URL object returned from the ClassLoader. This
retains any associated URLStreamHandler with the URL, which allows the
ClassLoader to return in-memory resources.

As an alternative to this change, projects that want to use in-memory
resources with Hazelcast could replace the URLStreamHandlerFactory, adding a
custom scheme for in-memory resources. However, that seems a more invasive
approach, with this change being strictly simpler.

Fixes #16846.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers Source: Community PR or issue was opened by a community user Team: Core Type: Defect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants