-
Notifications
You must be signed in to change notification settings - Fork 6.2k
6957241: ClassLoader.getResources() returns only 1 instance when using jar indexing #5316
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
Conversation
|
Hi @shiyuexw, welcome to this OpenJDK project and thanks for contributing! We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user shiyuexw" as summary for the issue. If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing |
|
/covered |
|
To avoid this situation, create a new branch for your changes and reset the Then proceed to create a new pull request with |
|
Thank you! Please allow for a few business days to verify that your employer has signed the OCA. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated! |
|
Thanks for the PR/patch. I think we need a discussion on core-libs-dev as to whether to keep the legacy JAR index support. The original motivation was applets when it was added in JDK 1.3. I don't think findResources has ever worked with the JAR index for cases where the same resource is in more than one JAR files. I'm not opposed to fixing it but it does add complexity and will likely refactoring the UCP implementation for something that will likely go away eventually anyway. |
|
If there is a way to simplify the UCP code by removing the support for legacy JAR index, and if it doesn't cause regressions, I'm all for it. But given the intricacy of that code I suspect it will be quite an undertaking - and reviewing such a change will probably not be trivial. The current PR is not trivial to review and seems to be adding an other layer of complexity though, so I agree that we should have this discussion. |
|
@wxiang I think there is at least some support for removing the JAR indexing support rather than trying to fix findResources. The issue of what to do with the legacy JAR index mechanism came up during JDK 9 in the context of modular JARs and also Multi-Release JARs but it was too much to take on at the time. Would you be interested in working out the changes to remove it? |
|
@AlanBateman Sure, I am interested in it. |
Great! I think there are several parts to this. The removal of the JAR index support from the URLClassLoader implementation, the It would be good to create a patch for the removal to see if there are any issues. There will probably need to be some discussion on what to do with the jar tool. I suspect we will need to keep the code that updates the index when updating a JAR file that has an existing index, this means keeping JarIndex and maybe moving it to the jdk.jartool module. We can change |
Depends on how draconian we're willing to be. At some point I can see the tool removing the index if it's updating a jar file that has one. Suitable warning messages would need to be emitted. |
I will first create the patch to remove JAR index support from the URLClassLoader implementation, the |
Thank you. We'll probably need a new JBS issue and PR for that but let's see first if any issues come out of the wood work. Stuart is right that another option for the jar tool is to drop the index when updating an existing JAR file that has an index, we don't need to decide that just yet. |
|
Mailing list message from Lance Andersen on core-libs-dev: On Sep 4, 2021, at 2:53 AM, Alan Bateman <alanb at openjdk.java.net<mailto:alanb at openjdk.java.net>> wrote: On Sat, 4 Sep 2021 01:53:35 GMT, wxiang <github.com+53162078+shiyuexw at openjdk.org<mailto:github.com+53162078+shiyuexw at openjdk.org>> wrote: I will first create the patch to remove JAR index support from the URLClassLoader implementation, the `jar i` option. Thank you. We'll probably need a new JBS issue and PR for that but let's see first if any issues come out of the wood work. Stuart is right that another option for the jar tool is to drop the index when updating an existing JAR file that has an index, we don't need to decide that just yet. Perhaps the jar validate option could/should be updated to flag when an index is there? We could add a warning for JDK 18 when main::genIndex is invoked as I assume we would want to at least wait until JDK19 to remove this functionality? Best ------------- PR: https://git.openjdk.java.net/jdk/pull/5316 [cid:E1C4E2F0-ECD0-4C9D-ADB4-B16CA7BCB7FC at home] Lance Andersen| Principal Member of Technical Staff | +1.781.442.2037 |
|
Mailing list message from Alan Bateman on core-libs-dev: On 04/09/2021 12:12, Lance Andersen wrote:
I'm not sure about jar --validate complaining if META-INF/INDEX.LIST is I don't think we really need to do anything to the jar tool in the short -Alan |
|
I created a new JBS https://bugs.openjdk.java.net/browse/JDK-8273401, and PR: #5383. |
|
JarIndex support will be deleted. close the PR. |
Using jarIndex for Hibench, there is an unexpected behavior with the exception "Exception in thread "main" org.apache.hadoop.fs.UnsupportedFileSystemException: No FileSystem for scheme "hdfs"".
After investigating it, it is related to the usage of ServiceLoader with JarIndex.
The below stack shows the issue with JDK11:
The below API tries to get all the resources with the same name.
After using JarIndex, URLClassPath.findResources only returns 1 URL.
It is the same as the description in JDK-6957241.
The issue still exists in JDK18.
Root cause:
With the JarIndex, there is only one loader which is corresponding to the jar with the index due to the implementation in JarLoader.getResource(final String name, boolean check, Set visited).
Loaders corresponding to other jar packages will not appear in this while.
So it only returns 1 instance.
To solve the issue, I change the implementation "private boolean next()".
If the loader has index, traverse the index and get all the resource from the loader.
Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5316/head:pull/5316$ git checkout pull/5316Update a local copy of the PR:
$ git checkout pull/5316$ git pull https://git.openjdk.java.net/jdk pull/5316/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 5316View PR using the GUI difftool:
$ git pr show -t 5316Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5316.diff