scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.88k stars 1.06k forks source link

SBT crashes when it tries to fetch the version of scala. #1388

Closed nicolasstucki closed 6 years ago

nicolasstucki commented 8 years ago

I found this while executing tests using sbt-dotty.

The issue is that sbt tries to fetch the version from scala.tools.nsc.Properties throug reflection.

Code in sbt.ScalaInstance.slowActualVersion that call it is:

val v = try { Class.forName("scala.tools.nsc.Properties", true, scalaLoader).getMethod("versionString").invoke(null).toString }
catch { case cause: Exception => throw new InvalidScalaInstance("Scala instance doesn't exist or is invalid: " + label, cause) }

The stacktrace is:

sbt.InvalidScalaInstance: Scala instance doesn't exist or is invalid: 
    version 0.1-SNAPSHOT, library jar: /Users/nastucki/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.5.jar, compiler jar: /Users/nastucki/.ivy2/local/ch.epfl.lamp/dotty_2.11/0.1-SNAPSHOT/jars/dotty_2.11.jar
    at sbt.ScalaInstance$.slowActualVersion(ScalaInstance.scala:130)
    at sbt.ScalaInstance$.sbt$ScalaInstance$$actualVersion(ScalaInstance.scala:127)
    at sbt.ScalaInstance$$anonfun$actualVersion$1.apply(ScalaInstance.scala:36)
    at sbt.ScalaInstance$$anonfun$actualVersion$1.apply(ScalaInstance.scala:36)
    at scala.Option.getOrElse(Option.scala:120)
    at sbt.ScalaInstance.actualVersion$lzycompute(ScalaInstance.scala:36)
    at sbt.ScalaInstance.actualVersion(ScalaInstance.scala:36)
    at sbt.compiler.MixedAnalyzingCompiler$.makeConfig(MixedAnalyzingCompiler.scala:121)
    at sbt.compiler.IC$.incrementalCompile(IncrementalCompiler.scala:130)
    at sbt.Compiler$.compile(Compiler.scala:152)
    at sbt.Compiler$.compile(Compiler.scala:138)
    at sbt.Defaults$.sbt$Defaults$$compileIncrementalTaskImpl(Defaults.scala:860)
    at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:851)
    at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:849)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sbt.ScalaInstance$.slowActualVersion(ScalaInstance.scala:130)
    at sbt.ScalaInstance$.sbt$ScalaInstance$$actualVersion(ScalaInstance.scala:127)
    at sbt.ScalaInstance$$anonfun$actualVersion$1.apply(ScalaInstance.scala:36)
    at sbt.ScalaInstance$$anonfun$actualVersion$1.apply(ScalaInstance.scala:36)
    at scala.Option.getOrElse(Option.scala:120)
    at sbt.ScalaInstance.actualVersion$lzycompute(ScalaInstance.scala:36)
    at sbt.ScalaInstance.actualVersion(ScalaInstance.scala:36)
    at sbt.compiler.MixedAnalyzingCompiler$.makeConfig(MixedAnalyzingCompiler.scala:121)
    at sbt.compiler.IC$.incrementalCompile(IncrementalCompiler.scala:130)
    at sbt.Compiler$.compile(Compiler.scala:152)
    at sbt.Compiler$.compile(Compiler.scala:138)
    at sbt.Defaults$.sbt$Defaults$$compileIncrementalTaskImpl(Defaults.scala:860)
    at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:851)
    at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:849)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ExceptionInInitializerError
    at scala.tools.nsc.Properties.versionString(Properties.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sbt.ScalaInstance$.slowActualVersion(ScalaInstance.scala:130)
    at sbt.ScalaInstance$.sbt$ScalaInstance$$actualVersion(ScalaInstance.scala:127)
    at sbt.ScalaInstance$$anonfun$actualVersion$1.apply(ScalaInstance.scala:36)
    at sbt.ScalaInstance$$anonfun$actualVersion$1.apply(ScalaInstance.scala:36)
    at scala.Option.getOrElse(Option.scala:120)
    at sbt.ScalaInstance.actualVersion$lzycompute(ScalaInstance.scala:36)
    at sbt.ScalaInstance.actualVersion(ScalaInstance.scala:36)
    at sbt.compiler.MixedAnalyzingCompiler$.makeConfig(MixedAnalyzingCompiler.scala:121)
    at sbt.compiler.IC$.incrementalCompile(IncrementalCompiler.scala:130)
    at sbt.Compiler$.compile(Compiler.scala:152)
    at sbt.Compiler$.compile(Compiler.scala:138)
    at sbt.Defaults$.sbt$Defaults$$compileIncrementalTaskImpl(Defaults.scala:860)
    at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:851)
    at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:849)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.zip.ZipException: invalid block type
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
    at java.io.FilterInputStream.read(FilterInputStream.java:133)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)
    at java.util.Properties$LineReader.readLine(Properties.java:435)
    at java.util.Properties.load0(Properties.java:353)
    at java.util.Properties.load(Properties.java:341)
    at scala.util.PropertiesTrait$$anonfun$scalaProps$1.apply$mcV$sp(Properties.scala:38)
    at scala.util.PropertiesTrait$class.quietlyDispose(Properties.scala:44)
    at scala.util.PropertiesTrait$class.scalaProps(Properties.scala:38)
    at scala.tools.nsc.Properties$.scalaProps$lzycompute(Properties.scala:10)
    at scala.tools.nsc.Properties$.scalaProps(Properties.scala:10)
    at scala.util.PropertiesTrait$class.scalaPropOrNone(Properties.scala:68)
    at scala.tools.nsc.Properties$.scalaPropOrNone(Properties.scala:10)
    at scala.util.PropertiesTrait$class.$init$(Properties.scala:80)
    at scala.tools.nsc.Properties$.<init>(Properties.scala:10)
    at scala.tools.nsc.Properties$.<clinit>(Properties.scala)
    at scala.tools.nsc.Properties.versionString(Properties.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sbt.ScalaInstance$.slowActualVersion(ScalaInstance.scala:130)
    at sbt.ScalaInstance$.sbt$ScalaInstance$$actualVersion(ScalaInstance.scala:127)
    at sbt.ScalaInstance$$anonfun$actualVersion$1.apply(ScalaInstance.scala:36)
    at sbt.ScalaInstance$$anonfun$actualVersion$1.apply(ScalaInstance.scala:36)
    at scala.Option.getOrElse(Option.scala:120)
    at sbt.ScalaInstance.actualVersion$lzycompute(ScalaInstance.scala:36)
    at sbt.ScalaInstance.actualVersion(ScalaInstance.scala:36)
    at sbt.compiler.MixedAnalyzingCompiler$.makeConfig(MixedAnalyzingCompiler.scala:121)
    at sbt.compiler.IC$.incrementalCompile(IncrementalCompiler.scala:130)
    at sbt.Compiler$.compile(Compiler.scala:152)
    at sbt.Compiler$.compile(Compiler.scala:138)
    at sbt.Defaults$.sbt$Defaults$$compileIncrementalTaskImpl(Defaults.scala:860)
    at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:851)
    at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:849)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
[error] (compile:compileIncremental) sbt.InvalidScalaInstance: Scala instance doesn't exist or is invalid: 
[error]     version 0.1-SNAPSHOT, library jar: /Users/nastucki/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.5.jar, compiler jar: /Users/nastucki/.ivy2/local/ch.epfl.lamp/dotty_2.11/0.1-SNAPSHOT/jars/dotty_2.11.jar

One hacky work around that I found is to add the following class in dotty

package sbt
object ScalaInstance {
  def slowActualVersion(): String = "2.11.8(dotty)"
}
nicolasstucki commented 8 years ago

This should be reproducible on https://github.com/nicolasstucki/dotty-project/tree/scalacheck using sbt test.

smarter commented 8 years ago

slowActualVersion is only called if fastActualVersion fails, this should not happen because the dotty jar should contain a compiler.properties file with the correct content ever since fc3221836bd28c98dbef64e564d6f4e8b6ae90db. Maybe when running the test the dotty jar is not present on the classpath?

smarter commented 6 years ago

Closing because this doesn't seem to be happening anymore.