-
Notifications
You must be signed in to change notification settings - Fork 322
Make classloader handling more compatible with JDK 9 #621
base: master-1.x
Are you sure you want to change the base?
Conversation
if (classLoader == ClassLoader.getSystemClassLoader()) { | ||
return Splitter.on(File.pathSeparatorChar) | ||
.splitToList(StandardSystemProperty.JAVA_CLASS_PATH.value()); | ||
} | ||
if (!(classLoader instanceof URLClassLoader)) { | ||
String message = String.format("Unable to use ClassLoader to detect classpath elements. " | ||
+ "Current ClassLoader is %s, only URLClassLoaders are supported.", classLoader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message should be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -3198,6 +3200,10 @@ public String toString() { | |||
* @return A list of absolute paths to the resources the class loader uses. | |||
*/ | |||
protected static List<String> detectClassPathResourcesToStage(ClassLoader classLoader) { | |||
if (classLoader == ClassLoader.getSystemClassLoader()) { | |||
return Splitter.on(File.pathSeparatorChar) | |||
.splitToList(StandardSystemProperty.JAVA_CLASS_PATH.value()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that the contents of the classpath are permitted to be relative paths, including directories, and the ClassLoader will search within each directory and JAR it finds on the classpath; so this may not return the absolute paths to all of the resources in all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it now makes the paths absolute.
Note that if the classpath contains directories URLClassLoader.getURLs
will return the URLs of those directories, so this doesn't change how directories are handled.
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.
From
http://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html: