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

[BEAM-2530] Make classloader handling more compatible with JDK 9 #4497

Closed
wants to merge 1 commit into from

Conversation

cushon
Copy link
Contributor

@cushon cushon commented Jan 26, 2018

From
http://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html:

The application class loader is no longer an instance of
java.net.URLClassLoader (an implementation detail that was never
specified in previous releases). Code that assumes that
ClassLoader::getSytemClassLoader returns a URLClassLoader object will
need to be updated. Note that Java SE and the JDK do not provide an
API for applications or libraries to dynamically augment the class
path at run-time.

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

@@ -37,6 +39,11 @@
* @return A list of absolute paths to the resources the class loader uses.
*/
public static List<String> detectClassPathResourcesToStage(ClassLoader classLoader) {
if (classLoader == ClassLoader.getSystemClassLoader()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this logic https://github.com/apache/geronimo-xbean/blob/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/ClassLoaders.java#L38 can be beneficial. High level idea is to use getResources() to determine what is in the classloader.

Copy link
Member

@lukecwik lukecwik Jan 26, 2018

Choose a reason for hiding this comment

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

Do you find in practice that all Java jars have a META-INF folder?

Also, it doesn't seem that getResources guarantees to return the same order of jars as specified on the classpath.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That isn't guaranteed to work for all jars - jar M will create an archive that doesn't contain a META-INF folder.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is why it is not the only strategy but likely the most portable i saw accross years. In particular in the context of this method. Do you expect all jars to be in the cp string? Not using manifest to load jars ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Neither approach is going to work in all cases, but I've had more success with this one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you test this class? getResources("") - not only metainf -
works on most jvm and supports all cases compared to classpath scanning which doesnt support a lot of bootstraps except plain mains :(.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tested this logic, but I haven't been able to test this specific usage of it. I ran into a similar problem I'm fixing in GoogleCloudPlatform/DataflowJavaSDK#621 and thought it was worth fixing here too.

If you'd like to defer until we're sure it's a problem, or implement the getResources approach instead, that's fine with me :)

Copy link
Member

Choose a reason for hiding this comment

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

I think this approach seems to solve a legitimate issue and other approaches can be implemented and added.

If you have a good idea on how to test this effectively since its easy to break this kind of functionality without knowing it.

Copy link
Contributor

Choose a reason for hiding this comment

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

to share the idea here what i had in mind high level #4514

@cushon cushon changed the title Make classloader handling more compatible with JDK 9 [BEAM-2530] Make classloader handling more compatible with JDK 9 Jan 26, 2018
From
http://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html:

> The application class loader is no longer an instance of
> java.net.URLClassLoader (an implementation detail that was never
> specified in previous releases). Code that assumes that
> ClassLoader::getSytemClassLoader returns a URLClassLoader object will
> need to be updated. Note that Java SE and the JDK do not provide an
> API for applications or libraries to dynamically augment the class
> path at run-time.
@lukecwik
Copy link
Member

I brought this discussion back to the dev@ to choose between PR/4497 or PR/4514 or support both.

@stale
Copy link

stale bot commented Jun 7, 2018

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 7, 2018
@stale
Copy link

stale bot commented Jun 14, 2018

This pull request has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@stale stale bot closed this Jun 14, 2018
@kennknowles kennknowles added stale and removed wontfix labels Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants