Skip to content

repl: Use the correct parent Classloader on Java 9+ #11658

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

Merged
merged 2 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion compiler/src/dotty/tools/repl/Rendering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
else {
val parent = parentClassLoader.getOrElse {
val compilerClasspath = ctx.platform.classPath(using ctx).asURLs
new java.net.URLClassLoader(compilerClasspath.toArray, null)
// We can't use the system classloader as a parent because it would
// pollute the user classpath with everything passed to the JVM
// `-classpath`. We can't use `null` as a parent either because on Java
// 9+ that's the bootstrap classloader which doesn't contain modules
// like `java.sql`, so we use the parent of the system classloader,
// which should correspond to the platform classloader on Java 9+.
val baseClassLoader = ClassLoader.getSystemClassLoader.getParent
new java.net.URLClassLoader(compilerClasspath.toArray, baseClassLoader)
}

myClassLoader = new AbstractFileClassLoader(ctx.settings.outputDir.value, parent)
Expand Down
3 changes: 3 additions & 0 deletions compiler/test-resources/repl/defaultClassloader
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scala> val d: java.sql.Date = new java.sql.Date(100L)
val d: java.sql.Date = 1970-01-01

2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/repl/ReplTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.na
}

object ReplTest:
val commonOptions = Array("-color:never", "-Yerased-terms")
val commonOptions = Array("-color:never", "-Yerased-terms", "-pagewidth", "80")
val defaultOptions = commonOptions ++ Array("-classpath", TestConfiguration.basicClasspath)
lazy val withStagingOptions = commonOptions ++ Array("-classpath", TestConfiguration.withStagingClasspath)