From dbf80a69d7eaf123b34207d8f60bb81401b2d469 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Mon, 8 Mar 2021 14:53:34 +0100 Subject: [PATCH 1/2] repl: Use the correct parent Classloader on Java 9+ On Java 9+, `null` as a parent of a URLClassLoader means the parent is the bootstrap classloader which doesn't contain modules like `java.sql`, explicitly use the platform classloader instead. Fixes #11646. --- compiler/src/dotty/tools/repl/Rendering.scala | 9 ++++++++- compiler/test-resources/repl/defaultClassloader | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 compiler/test-resources/repl/defaultClassloader diff --git a/compiler/src/dotty/tools/repl/Rendering.scala b/compiler/src/dotty/tools/repl/Rendering.scala index f91fa94ab8f9..e07cb867062d 100644 --- a/compiler/src/dotty/tools/repl/Rendering.scala +++ b/compiler/src/dotty/tools/repl/Rendering.scala @@ -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) diff --git a/compiler/test-resources/repl/defaultClassloader b/compiler/test-resources/repl/defaultClassloader new file mode 100644 index 000000000000..ac42150e14d4 --- /dev/null +++ b/compiler/test-resources/repl/defaultClassloader @@ -0,0 +1,3 @@ +scala> val d: java.sql.Date = new java.sql.Date(100L) +val d: java.sql.Date = 1970-01-01 + From 4f803eba2c9a942b5af8643393243537a2c1b195 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Mon, 8 Mar 2021 15:03:05 +0100 Subject: [PATCH 2/2] Fix scripted test failures due to auto-detected pagewidth --- compiler/test/dotty/tools/repl/ReplTest.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test/dotty/tools/repl/ReplTest.scala b/compiler/test/dotty/tools/repl/ReplTest.scala index 841f8492a7b3..6fa5b6648bf6 100644 --- a/compiler/test/dotty/tools/repl/ReplTest.scala +++ b/compiler/test/dotty/tools/repl/ReplTest.scala @@ -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)