Skip to content

Commit 0dbe970

Browse files
authored
Merge pull request #11658 from dotty-staging/repl-classloader
repl: Use the correct parent Classloader on Java 9+
2 parents 22a9a5a + 4f803eb commit 0dbe970

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

compiler/src/dotty/tools/repl/Rendering.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
4747
else {
4848
val parent = parentClassLoader.getOrElse {
4949
val compilerClasspath = ctx.platform.classPath(using ctx).asURLs
50-
new java.net.URLClassLoader(compilerClasspath.toArray, null)
50+
// We can't use the system classloader as a parent because it would
51+
// pollute the user classpath with everything passed to the JVM
52+
// `-classpath`. We can't use `null` as a parent either because on Java
53+
// 9+ that's the bootstrap classloader which doesn't contain modules
54+
// like `java.sql`, so we use the parent of the system classloader,
55+
// which should correspond to the platform classloader on Java 9+.
56+
val baseClassLoader = ClassLoader.getSystemClassLoader.getParent
57+
new java.net.URLClassLoader(compilerClasspath.toArray, baseClassLoader)
5158
}
5259

5360
myClassLoader = new AbstractFileClassLoader(ctx.settings.outputDir.value, parent)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
scala> val d: java.sql.Date = new java.sql.Date(100L)
2+
val d: java.sql.Date = 1970-01-01
3+

compiler/test/dotty/tools/repl/ReplTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.na
9494
}
9595

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

0 commit comments

Comments
 (0)