Skip to content

JAR files whose path contains a space cannot be added to the REPL classpath #11565

Open
@dbdahl

Description

@dbdahl

JAR files whose path contains a space cannot be added to the REPL classpath:

$intp.addUrlsToClassPath(new java.io.File("directory with spaces/hello.jar").toURI.toURL)

Welcome to Scala 2.13.0 (OpenJDK 64-Bit Server VM, Java 11.0.3).
Type in expressions for evaluation. Or try :help.

scala> $intp.addUrlsToClassPath(new java.io.File("directory with space/hello.jar").toURI.toURL)
java.lang.NullPointerException
at scala.tools.nsc.Global.assoc$1(Global.scala:877)
at scala.tools.nsc.Global.$anonfun$invalidateClassPathEntries$2(Global.scala:892)
at scala.collection.StrictOptimizedIterableOps.flatMap(StrictOptimizedIterableOps.scala:118)
at scala.collection.StrictOptimizedIterableOps.flatMap$(StrictOptimizedIterableOps.scala:105)
at scala.collection.immutable.ArraySeq.flatMap(ArraySeq.scala:34)
at scala.tools.nsc.Global.invalidateClassPathEntries(Global.scala:892)
at scala.tools.nsc.Global.extendCompilerClassPath(Global.scala:827)
at scala.tools.nsc.interpreter.IMain.addUrlsToClassPath(IMain.scala:241)
... 28 elided

In contrast, the JAR is successfully added if its path contains no spaces:

$intp.addUrlsToClassPath(new java.io.File("directoryWithoutSpaces/hello.jar").toURI.toURL)

Note that this issue is also manifest using REPL's ":require" feature. I have reproduced this bug in both Scala 2.13.0 & 2.12.8 and both Ubuntu 18.04 and Windows 10.

This seems to be related to #9405 but that report deals with directories, whereas this report deals with spaces in paths.

By way of context, this bug is affecting my rscala package, which allows R packages to be written in Scala. In that context, users of may have little control over whether or not a JAR file embedded within a package has a space in its full path. My current work-around is to copy the JAR to a location without a space and load it from there.

I'd love to have the bug fixed but don't think I have the skills to attack it myself. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions