Skip to content
This repository has been archived by the owner on Nov 11, 2022. It is now read-only.

Make classloader handling more compatible with JDK 9 #621

Open
wants to merge 1 commit into
base: master-1.x
Choose a base branch
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.

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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());
Copy link
Contributor

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.

Copy link
Contributor Author

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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants