-
-
Notifications
You must be signed in to change notification settings - Fork 330
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
Fix #370 Use ExtClassLoader instead of null as parent #1848
Conversation
scalalib/test/resources/classloader-test/test/src/ClassLoaderTests.scala
Outdated
Show resolved
Hide resolved
} else { | ||
// With Java 8 we want a clean classloader that still contains classes | ||
// coming from com.sun.* etc. | ||
// We get the application classloader parent which happens to be of | ||
// type sun.misc.Launcher$ExtClassLoader | ||
// We can't call the method directly since it doesn't exist in Java 9 | ||
// So we load it via reflection. | ||
val launcherClass = getClass.getClassLoader().loadClass("sun.misc.Launcher") | ||
val getLauncherMethod = launcherClass.getMethod("getLauncher") | ||
val launcher = getLauncherMethod.invoke(null) | ||
val getClassLoaderMethod = launcher.getClass().getMethod("getClassLoader") | ||
val appClassLoader = getClassLoaderMethod.invoke(launcher).asInstanceOf[ClassLoader] | ||
appClassLoader.getParent() |
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.
Why do we load this code via reflection, when we are only supposed to run it on Java 8? Is this more the kind of compile-time work-around?
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.
The code doesn't compile in Java 9+. I used reflection to allow compilation of Mill in Java 9+ since the sun.misc
package doesn't exist in Java 9+.
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 for clarifying. I think the comment is kind of abḿbigous. Maybe, you can add, that reflection solved an issue at compilation-time?
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.
Rephrased the commend a bit.
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.
Looks good to me. Now, we need to find out. why this isn't working on Windows. 🤔
It was not happy with |
No description provided.