Skip to content

Commit dbf80a6

Browse files
committed
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.
1 parent 3b524a4 commit dbf80a6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
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+

0 commit comments

Comments
 (0)