scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Could not launch Scala 2.10.7, 2.11.12 REPL with Java 11 (without `-nobootcp -nc` workaround) #10603

Closed xuwei-k closed 3 years ago

xuwei-k commented 7 years ago
$ java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
$ scala -version
Scala code runner version 2.10.7 -- Copyright 2002-2017, LAMP/EPFL
$ scala
Welcome to Scala version 2.10.7 (Java HotSpot(TM) 64-Bit Server VM, Java 9.0.1).
Type in expressions to have them evaluated.
Type :help for more information.

scala> 
Failed to initialize compiler: NoClassDefFoundError.
This is most often remedied by a full clean and recompile.
Otherwise, your classpath may continue bytecode compiled by
different and incompatible versions of scala.

java.lang.NoClassDefFoundError: javax/tools/ToolProvider
    at scala.reflect.io.JavaToolsPlatformArchive.iterator(ZipArchive.scala:242)
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
    at scala.reflect.io.AbstractFile.foreach(AbstractFile.scala:92)
    at scala.tools.nsc.util.DirectoryClassPath.traverse(ClassPath.scala:308)
    at scala.tools.nsc.util.DirectoryClassPath.x$16$lzycompute(ClassPath.scala:317)
    at scala.tools.nsc.util.DirectoryClassPath.x$16(ClassPath.scala:317)
    at scala.tools.nsc.util.DirectoryClassPath.packages$lzycompute(ClassPath.scala:317)
    at scala.tools.nsc.util.DirectoryClassPath.packages(ClassPath.scala:317)
    at scala.tools.nsc.util.DirectoryClassPath.packages(ClassPath.scala:297)
    at scala.tools.nsc.util.MergedClassPath$$anonfun$packages$1.apply(ClassPath.scala:375)
    at scala.tools.nsc.util.MergedClassPath$$anonfun$packages$1.apply(ClassPath.scala:375)
    at scala.collection.Iterator$class.foreach(Iterator.scala:727)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
    at scala.tools.nsc.util.MergedClassPath.packages$lzycompute(ClassPath.scala:375)
    at scala.tools.nsc.util.MergedClassPath.packages(ClassPath.scala:370)
    at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader.doComplete(SymbolLoaders.scala:243)
    at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:194)
    at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1231)
    at scala.reflect.internal.Mirrors$RootsBase.init(Mirrors.scala:240)
    at scala.tools.nsc.Global.rootMirror$lzycompute(Global.scala:59)
    at scala.tools.nsc.Global.rootMirror(Global.scala:57)
    at scala.tools.nsc.Global.rootMirror(Global.scala:37)
    at scala.reflect.internal.Definitions$DefinitionsClass.<init>(Definitions.scala:166)
    at scala.reflect.internal.Definitions$definitions$.<init>(Definitions.scala:20)
    at scala.reflect.internal.SymbolTable.definitions$lzycompute(SymbolTable.scala:13)
    at scala.reflect.internal.SymbolTable.definitions(SymbolTable.scala:13)
    at scala.tools.nsc.Global$Run.<init>(Global.scala:1290)
    at scala.tools.nsc.interpreter.IMain.scala$tools$nsc$interpreter$IMain$$_initialize(IMain.scala:149)
    at scala.tools.nsc.interpreter.IMain$$anonfun$initialize$1.apply$mcZ$sp(IMain.scala:162)
    at scala.tools.nsc.interpreter.IMain$$anonfun$initialize$1.apply(IMain.scala:162)
    at scala.tools.nsc.interpreter.IMain$$anonfun$initialize$1.apply(IMain.scala:162)
    at scala.tools.nsc.io.package$$anon$3.call(package.scala:40)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.base/java.lang.Thread.run(Thread.java:844)

Failed to initialize the REPL due to an unexpected error.
This is a bug, please, report it along with the error diagnostics printed below.
java.lang.NullPointerException
    at scala.tools.nsc.interpreter.ExprTyper$codeParser$.applyRule(ExprTyper.scala:24)
    at scala.tools.nsc.interpreter.ExprTyper$codeParser$.stmts(ExprTyper.scala:35)
    at scala.tools.nsc.interpreter.ExprTyper$$anonfun$parse$2.apply(ExprTyper.scala:43)
    at scala.tools.nsc.interpreter.ExprTyper$$anonfun$parse$2.apply(ExprTyper.scala:42)
    at scala.tools.nsc.reporters.Reporter.withIncompleteHandler(Reporter.scala:51)
    at scala.tools.nsc.interpreter.ExprTyper$class.parse(ExprTyper.scala:42)
    at scala.tools.nsc.interpreter.IMain$exprTyper$.parse(IMain.scala:1074)
    at scala.tools.nsc.interpreter.IMain.parse(IMain.scala:1078)
    at scala.tools.nsc.interpreter.IMain$$anonfun$showCodeIfDebugging$1.apply(IMain.scala:1168)
    at scala.tools.nsc.interpreter.IMain$$anonfun$showCodeIfDebugging$1.apply(IMain.scala:1168)
    at scala.tools.nsc.interpreter.IMain.beSilentDuring(IMain.scala:238)
    at scala.tools.nsc.interpreter.IMain.showCodeIfDebugging(IMain.scala:1168)
    at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compileAndSaveRun(IMain.scala:800)
    at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compile(IMain.scala:761)
    at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:618)
    at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:661)
    at scala.tools.nsc.interpreter.IMain$$anonfun$quietBind$1.apply(IMain.scala:660)
    at scala.tools.nsc.interpreter.IMain$$anonfun$quietBind$1.apply(IMain.scala:660)
    at scala.tools.nsc.interpreter.IMain.beQuietDuring(IMain.scala:232)
    at scala.tools.nsc.interpreter.IMain.quietBind(IMain.scala:660)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1$$anonfun$apply$mcZ$sp$2.apply$mcV$sp(ILoop.scala:853)
    at scala.tools.nsc.interpreter.ILoopInit$class.runThunks(ILoopInit.scala:122)
    at scala.tools.nsc.interpreter.ILoop.runThunks(ILoop.scala:42)
    at scala.tools.nsc.interpreter.ILoopInit$class.postInitialization(ILoopInit.scala:95)
    at scala.tools.nsc.interpreter.ILoop.postInitialization(ILoop.scala:42)
    at scala.tools.nsc.interpreter.ILoopInit$$anonfun$createAsyncListener$1.apply$mcV$sp(ILoopInit.scala:63)
    at scala.tools.nsc.interpreter.ILoopInit$$anonfun$createAsyncListener$1.apply(ILoopInit.scala:60)
    at scala.tools.nsc.interpreter.ILoopInit$$anonfun$createAsyncListener$1.apply(ILoopInit.scala:60)
    at scala.tools.nsc.io.package$$anon$3.call(package.scala:40)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.base/java.lang.Thread.run(Thread.java:844)
$ java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
$ scala -version
Scala code runner version 2.11.12 -- Copyright 2002-2017, LAMP/EPFL
$ scala
Welcome to Scala 2.11.12 (Java HotSpot(TM) 64-Bit Server VM, Java 9.0.1).
Type in expressions for evaluation. Or try :help.
Exception in thread "main" 
scala> java.lang.NoClassDefFoundError: javax/script/Compilable
    at scala.tools.nsc.interpreter.ILoop.createInterpreter(ILoop.scala:118)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1$$anonfun$startup$1$1$$anonfun$apply$1.apply(ILoop.scala:971)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1$$anonfun$startup$1$1$$anonfun$apply$1.apply(ILoop.scala:971)
    at scala.tools.nsc.interpreter.ILoop.savingReader(ILoop.scala:96)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1$$anonfun$startup$1$1.apply(ILoop.scala:970)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:990)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:891)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:891)
    at scala.reflect.internal.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:97)
    at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:891)
    at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:74)
    at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:87)
    at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:98)
    at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:103)
    at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
[ERROR] Failed to disable litteral next character
java.lang.InterruptedException
    at java.base/java.lang.Object.wait(Native Method)
    at java.base/java.lang.Object.wait(Object.java:516)
    at java.base/java.lang.ProcessImpl.waitFor(ProcessImpl.java:494)
    at jline.internal.TerminalLineSettings.waitAndCapture(TerminalLineSettings.java:339)
    at jline.internal.TerminalLineSettings.exec(TerminalLineSettings.java:311)
    at jline.internal.TerminalLineSettings.stty(TerminalLineSettings.java:282)
    at jline.internal.TerminalLineSettings.undef(TerminalLineSettings.java:158)
    at jline.UnixTerminal.disableLitteralNextCharacter(UnixTerminal.java:194)
    at jline.console.ConsoleReader.readLine(ConsoleReader.java:2450)
    at jline.console.ConsoleReader.readLine(ConsoleReader.java:2373)
    at jline.console.ConsoleReader.readLine(ConsoleReader.java:2361)
    at scala.tools.nsc.interpreter.jline.InteractiveReader.readOneLine(JLineReader.scala:59)
    at scala.tools.nsc.interpreter.InteractiveReader$$anonfun$readLine$2.apply(InteractiveReader.scala:37)
    at scala.tools.nsc.interpreter.InteractiveReader$$anonfun$readLine$2.apply(InteractiveReader.scala:37)
    at scala.tools.nsc.interpreter.InteractiveReader$.restartSysCalls(InteractiveReader.scala:44)
    at scala.tools.nsc.interpreter.InteractiveReader$class.readLine(InteractiveReader.scala:37)
    at scala.tools.nsc.interpreter.jline.InteractiveReader.readLine(JLineReader.scala:27)
    at scala.tools.nsc.interpreter.SplashReader.readLine(InteractiveReader.scala:142)
    at scala.tools.nsc.interpreter.SplashLoop.run(InteractiveReader.scala:71)
    at java.base/java.lang.Thread.run(Thread.java:844)

Exception in thread "Thread-1" java.lang.InterruptedException
    at java.base/java.util.concurrent.SynchronousQueue.put(SynchronousQueue.java:875)
    at scala.tools.nsc.interpreter.SplashLoop.run(InteractiveReader.scala:77)
    at java.base/java.lang.Thread.run(Thread.java:844)
adriaanm commented 7 years ago

Workaround (sorry, forgot in release notes!): -nobootcp -nc

xuwei-k commented 7 years ago

Workaround (sorry, forgot in release notes!): -nobootcp -nc

Thanks!

adriaanm commented 7 years ago

Thank you very much for testing and reporting. I updated the release notes

xuwei-k commented 7 years ago

I just realized not only REPL

but scalac -nobootcp A.scala works 😃

som-snytt commented 7 years ago

The spelling of Failed to disable litteral next character is due to jline.

zxxc commented 6 years ago

same issue when i'm trying to start sbt


Java HotSpot(TM) 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
java.lang.NullPointerException
        at scala.reflect.io.JavaToolsPlatformArchive.iterator(ZipArchive.scala:242)
        at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
        at scala.reflect.io.AbstractFile.foreach(AbstractFile.scala:92)
        at scala.tools.nsc.util.DirectoryClassPath.traverse(ClassPath.scala:308)
        at scala.tools.nsc.util.DirectoryClassPath.x$16$lzycompute(ClassPath.scala:317)
        at scala.tools.nsc.util.DirectoryClassPath.x$16(ClassPath.scala:317)
        at scala.tools.nsc.util.DirectoryClassPath.packages$lzycompute(ClassPath.scala:317)
        at scala.tools.nsc.util.DirectoryClassPath.packages(ClassPath.scala:317)
        at scala.tools.nsc.util.DirectoryClassPath.packages(ClassPath.scala:297)
        at scala.tools.nsc.util.MergedClassPath$$anonfun$packages$1.apply(ClassPath.scala:375)
        at scala.tools.nsc.util.MergedClassPath$$anonfun$packages$1.apply(ClassPath.scala:375)
        at scala.collection.Iterator$class.foreach(Iterator.scala:727)
        at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
        at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
        at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
        at scala.tools.nsc.util.MergedClassPath.packages$lzycompute(ClassPath.scala:375)
        at scala.tools.nsc.util.MergedClassPath.packages(ClassPath.scala:370)
        at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader.doComplete(SymbolLoaders.scala:243)
        at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:194)
        at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1231)```
SethTisue commented 6 years ago

@zxxc make sure you're using sbt 0.13.17 or the latest 1.1.x; older versions don't work on Java 9 (I forget exactly when in the 1.x series support started). check project/build.properties as well as whatever launcher you have installed. if this is mysterious, see https://www.scala-sbt.org/support.html for where to seek further help with sbt

er1c commented 5 years ago

I just ran into this issue while playing with bloop, and zinc for java11. Adding the command line args doesn't seem very desireable. I believe tools.jar ("jdk.tools" % "jdk.tools" % "1.8" % "system") was removed in java9 (http://openjdk.java.net/jeps/220) so simply adding the dependency explicitly should fix this issue.

Quick Edit: These are now MODULES and not just libraries that can be included. So slightly more complicated.

adriaanm commented 5 years ago

/cc @jvican -- something to consider fixing on the bloop runner side of things?

dwijnand commented 5 years ago

For reasons unknown (and perhaps I should find out) this doesn't reproduce with the coursier-based runners ([1]):

15:10:31 $ java -version
openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.3+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.3+7, mixed mode)

15:10:33 $ scala -210
Failed to created JLineReader: java.lang.NoClassDefFoundError: scala/tools/jline/console/ConsoleReader
Falling back to SimpleReader.
Welcome to Scala version 2.10.7 (OpenJDK 64-Bit Server VM, Java 11.0.3).
Type in expressions to have them evaluated.
Type :help for more information.

scala> "2.10.7"
res0: String = 2.10.7

scala> ^D
15:10:45 $ scala -211
Welcome to Scala 2.11.12 (OpenJDK 64-Bit Server VM, Java 11.0.3).
Type in expressions for evaluation. Or try :help.

scala> "2.11.12"
res0: String = 2.11.12

scala> :quit
jvican commented 5 years ago

@er1c Did the error go away with latest Bloop version? I remember you sent some patches to fix Bloop on Java 9+ but I'm not sure if they fixed this particular issue.

SethTisue commented 3 years ago

Closing, since 2.10 and 2.11 development have ceased and the problem doesn't exist in later Scala versions.

som-snytt commented 3 years ago

Hopefully there is still a ticket to make -nobootcp the default.

tacerus commented 2 years ago

Hi, is this supposed to still be an issue?

$ scala
Welcome to Scala version 2.10.7 (OpenJDK 64-Bit Server VM, Java 11.0.13).
Type in expressions to have them evaluated.
Type :help for more information.

scala> 
Failed to initialize compiler: NoClassDefFoundError.
This is most often remedied by a full clean and recompile.
Otherwise, your classpath may continue bytecode compiled by
different and incompatible versions of scala.

java.lang.NoClassDefFoundError: javax/tools/ToolProvider
    at scala.reflect.io.JavaToolsPlatformArchive.iterator(ZipArchive.scala:242)
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
    at scala.reflect.io.AbstractFile.foreach(AbstractFile.scala:92)
    at scala.tools.nsc.util.DirectoryClassPath.traverse(ClassPath.scala:308)
    at scala.tools.nsc.util.DirectoryClassPath.x$16$lzycompute(ClassPath.scala:317)
    at scala.tools.nsc.util.DirectoryClassPath.x$16(ClassPath.scala:317)
    at scala.tools.nsc.util.DirectoryClassPath.packages$lzycompute(ClassPath.scala:317)
    at scala.tools.nsc.util.DirectoryClassPath.packages(ClassPath.scala:317)
    at scala.tools.nsc.util.DirectoryClassPath.packages(ClassPath.scala:297)
    at scala.tools.nsc.util.MergedClassPath$$anonfun$packages$1.apply(ClassPath.scala:375)
    at scala.tools.nsc.util.MergedClassPath$$anonfun$packages$1.apply(ClassPath.scala:375)
    at scala.collection.Iterator$class.foreach(Iterator.scala:727)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
    at scala.tools.nsc.util.MergedClassPath.packages$lzycompute(ClassPath.scala:375)
    at scala.tools.nsc.util.MergedClassPath.packages(ClassPath.scala:370)
    at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader.doComplete(SymbolLoaders.scala:243)
    at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:194)
    at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1231)
    at scala.reflect.internal.Mirrors$RootsBase.init(Mirrors.scala:240)
    at scala.tools.nsc.Global.rootMirror$lzycompute(Global.scala:59)
    at scala.tools.nsc.Global.rootMirror(Global.scala:57)
    at scala.tools.nsc.Global.rootMirror(Global.scala:37)
    at scala.reflect.internal.Definitions$DefinitionsClass.<init>(Definitions.scala:166)
    at scala.reflect.internal.Definitions$definitions$.<init>(Definitions.scala:20)
    at scala.reflect.internal.SymbolTable.definitions$lzycompute(SymbolTable.scala:13)
    at scala.reflect.internal.SymbolTable.definitions(SymbolTable.scala:13)
    at scala.tools.nsc.Global$Run.<init>(Global.scala:1290)
    at scala.tools.nsc.interpreter.IMain.scala$tools$nsc$interpreter$IMain$$_initialize(IMain.scala:149)
    at scala.tools.nsc.interpreter.IMain$$anonfun$ini
$ scala -nobootcp
Welcome to Scala version 2.10.7 (OpenJDK 64-Bit Server VM, Java 11.0.13).
Type in expressions to have them evaluated.
Type :help for more information.

scala> 

I tried this with:

$ java -version
openjdk version "11.0.13" 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-suse-2.3-x8664)
OpenJDK 64-Bit Server VM (build 11.0.13+8-suse-2.3-x8664, mixed mode)
$ java -version
openjdk version "11.0.14.1" 2022-02-08
OpenJDK Runtime Environment (build 11.0.14.1+1-suse-2.1-x8664)
OpenJDK 64-Bit Server VM (build 11.0.14.1+1-suse-2.1-x8664, mixed mode)
$ java -version
openjdk version "11.0.14.1" 2022-02-08
OpenJDK Runtime Environment Temurin-11.0.14.1+1 (build 11.0.14.1+1)
OpenJDK 64-Bit Server VM Temurin-11.0.14.1+1 (build 11.0.14.1+1, mixed mode)
$ java -version
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment Temurin-17.0.2+8 (build 17.0.2+8)
OpenJDK 64-Bit Server VM Temurin-17.0.2+8 (build 17.0.2+8, mixed mode, sharing)

and

scala> util.Properties.versionString 
res0: String = version 2.10.7
SethTisue commented 2 years ago

Hi, is this supposed to still be an issue?

Yes, we're aware the problem still exists in 2.10.7 and 2.11.12. As I wrote earlier:

Closing, since 2.10 and 2.11 development have ceased and the problem doesn't exist in later Scala versions

We only keep a ticket open if the problem still exists in the HEAD of the current development branch (namely 2.13.x).

som-snytt commented 2 years ago

@tacerus The getting started page https://docs.scala-lang.org/getting-started/index.html links to the JDK matrix https://docs.scala-lang.org/overviews/jdk-compatibility/overview.html

The somewhat orthogonal issue of coping with classloaders and modules, either from CLI or other environments, is ongoing.

tacerus commented 2 years ago

Ah, apologies @SethTisue, I missed the version issue - I will attempt the latest release! Thanks!

Thank you @som-snytt for linking the version matrix, that is very helpful!