Run scala REPL in windows cmd, appear java.lang.NullPointerException

Hello:
When I execute “scala” in the cmd, it report an Exception like this:

The whole console information is:

Microsoft Windows [版本 10.0.15063]
© 2017 Microsoft Corporation。保留所有权利。

C:\Users\clz>scala
Welcome to Scala 2.12.2 (Java HotSpot™ 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.

scala> Exception in thread “main” java.lang.NullPointerException
at java.util.Arrays.sort(Arrays.java:1438)
at scala.tools.nsc.classpath.JFileDirectoryLookup.listChildren(DirectoryClassPath.scala:112)
at scala.tools.nsc.classpath.JFileDirectoryLookup.listChildren$(DirectoryClassPath.scala:96)
at scala.tools.nsc.classpath.DirectoryClassPath.listChildren(DirectoryClassPath.scala:199)
at scala.tools.nsc.classpath.DirectoryClassPath.listChildren(DirectoryClassPath.scala:199)
at scala.tools.nsc.classpath.DirectoryLookup.list(DirectoryClassPath.scala:72)
at scala.tools.nsc.classpath.DirectoryLookup.list$(DirectoryClassPath.scala:68)
at scala.tools.nsc.classpath.DirectoryClassPath.list(DirectoryClassPath.scala:199)
at scala.tools.nsc.classpath.AggregateClassPath.$anonfun$list$1(AggregateClassPath.scala:78)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.Iterator.foreach(Iterator.scala:929)
at scala.collection.Iterator.foreach$(Iterator.scala:929)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1417)
at scala.collection.IterableLike.foreach(IterableLike.scala:71)
at scala.collection.IterableLike.foreach$(IterableLike.scala:70)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.TraversableLike.map(TraversableLike.scala:234)
at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at scala.tools.nsc.classpath.AggregateClassPath.list(AggregateClassPath.scala:76)
at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader.doComplete(SymbolLoaders.scala:269)
at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:218)
at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1521)
at scala.reflect.internal.Mirrors$RootsBase.init(Mirrors.scala:225)
at scala.tools.nsc.Global.rootMirror$lzycompute(Global.scala:63)
at scala.tools.nsc.Global.rootMirror(Global.scala:61)
at scala.tools.nsc.Global.rootMirror(Global.scala:34)
at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass$lzycompute(Definitions.scala:267)
at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass(Definitions.scala:267)
at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1446)
at scala.tools.nsc.Global$Run.(Global.scala:1149)
at scala.tools.nsc.interpreter.IMain._initialize(IMain.scala:127)
at scala.tools.nsc.interpreter.IMain.initializeSynchronous(IMain.scala:149)
at scala.tools.nsc.interpreter.ILoop.$anonfun$process$11(ILoop.scala:992)
at scala.tools.nsc.interpreter.ILoop.startup$1(ILoop.scala:964)
at scala.tools.nsc.interpreter.ILoop.$anonfun$process$1(ILoop.scala:1009)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:909)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:75)
at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:88)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:99)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:104)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

How can I resolve this problem?
Thanks.:slight_smile:

Hello,

How did you install Scala?

 Best, Oliver

I had the same issue with AdoptJDK. I changed to OpenJDK and OracleJDK, and it worked fine after.

1 Like

Did you have that issue at least somewhat recently? I can’t reproduce with 2.13.2:

C:\Users\marti>java -version
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.7+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.7+10, mixed mode)

C:\Users\marti>echo %java_home%
C:\Program Files\AdoptOpenJDK\jdk-11.0.7.10-hotspot

C:\Users\marti>echo %jdk_home%
C:\Program Files\AdoptOpenJDK\jdk-11.0.7.10-hotspot

C:\Users\marti>scala
Welcome to Scala 2.13.2 (OpenJDK 64-Bit Server VM, Java 11.0.7).
Type in expressions for evaluation. Or try :help.

scala> val hello = "AdoptOpenJDK"
val hello: String = AdoptOpenJDK

scala>

Yes I did, with Adopt OpenJDK 8 with Scala 2.12.10 in msys2 and Adopt OpenJDK 13 with Scala 2.13.2 in WSL. Changed to Azul and it worked fine.

Can you post the full stack trace?

For 2.13.2/AdoptOpenJDK 11/msys2 for me it’s fine:

marti@LAPTOP-7MK8D0M5 MINGW64 ~
$ java --version
openjdk 11.0.7 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.7+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.7+10, mixed mode)

marti@LAPTOP-7MK8D0M5 MINGW64 ~
$ scala
Welcome to Scala 2.13.2 (OpenJDK 64-Bit Server VM, Java 11.0.7).
Type in expressions for evaluation. Or try :help.

scala> val hello = "msys2"
val hello: String = msys2

scala>
:quit

I’ve seen shenanigans before where java_home and the java on the path aren’t the same and one or the other is a non-SDK distribution, but this doesn’t seem to be that.

How did you install scala and the jdk on the environments you mention? I want to see if I can reproduce this. I’d love to be able to recommend everyone just AdoptOpenJDK, so fixing this would be nice.