Failing to run tests from sbt test

I’m trying to run my project tests from sbt at the command line with “sbt test”.
But I get errors that I don’t understand.

Does anyone have an idea of what’s happening here?

I’m not sure whether this is related to another issue, that I cannot run the tests en masse from IntelliJ.

[geminiani:~/Repos/regular-type-expression/cl-robdd-scala] jimka% sbt test
[info] Loading settings for project global-plugins from idea.sbt ...
[info] Loading global plugins from /Users/jimka/.sbt/1.0/plugins
[info] Loading project definition from /Users/jimka/Repos/regular-type-expression/cl-robdd-scala/project
[info] Loading settings for project cl-robdd-scala from build.sbt ...
[info] Set current project to cl-robdd-scala (in build file:/Users/jimka/Repos/regular-type-expression/cl-robdd-scala/)
[info] Compiling 29 Scala sources to /Users/jimka/Repos/regular-type-expression/cl-robdd-scala/target/scala-2.12/classes ...
[warn] /Users/jimka/Repos/regular-type-expression/cl-robdd-scala/src/main/scala/dfa/Dfa.scala:20:55: abstract type pattern L is unchecked since it is eliminated by erasure
[warn]   require(protoDelta.forall { case (from: Int, label: L, to: Int) => Qids.contains(from) && Qids.contains(to) })
[warn]                                                       ^
[warn] /Users/jimka/Repos/regular-type-expression/cl-robdd-scala/src/main/scala/treereduce/ListSpecificTreeReduce.scala:44:51: abstract type pattern A is unchecked since it is eliminated by erasure
[warn]         val reduced: List[A] = { case (b1: A, b2: A) => f(b1, b2) }
[warn]                                                   ^
[warn] /Users/jimka/Repos/regular-type-expression/cl-robdd-scala/src/main/scala/treereduce/ListSpecificTreeReduce.scala:44:58: abstract type pattern A is unchecked since it is eliminated by erasure
[warn]         val reduced: List[A] = { case (b1: A, b2: A) => f(b1, b2) }
[warn]                                                          ^
[error] ## Exception when compiling 29 sources to /Users/jimka/Repos/regular-type-expression/cl-robdd-scala/target/scala-2.12/classes
[error] java.lang.RuntimeException: /packages cannot be represented as URI
[error] java.base/jdk.internal.jrtfs.JrtPath.toUri(
[error] scala.collection.TraversableLike.$anonfun$flatMap$1(TraversableLike.scala:244)
[error] scala.collection.Iterator.foreach(Iterator.scala:941)
[error] scala.collection.Iterator.foreach$(Iterator.scala:941)
[error] scala.collection.AbstractIterator.foreach(Iterator.scala:1429)
[error] scala.collection.IterableLike.foreach(IterableLike.scala:74)
[error] scala.collection.IterableLike.foreach$(IterableLike.scala:73)
[error] scala.collection.AbstractIterable.foreach(Iterable.scala:56)
[error] scala.collection.TraversableLike.flatMap(TraversableLike.scala:244)
[error] scala.collection.TraversableLike.flatMap$(TraversableLike.scala:241)
[error] scala.collection.AbstractTraversable.flatMap(Traversable.scala:108)

This is a serious warning that should also be visible in IntelliJ. Type patterns always match type variables, and you can easily introduce unsoundness to your program by doing this.

@ def unsound[A](as: List[Any]): List[A] = { case a: A => a } abstract type pattern A is unchecked since it is eliminated by erasure
def unsound[A](as: List[Any]): List[A] = { case a: A => a }
defined function unsound

@ val wat = unsound[Int](List(true, "hello", 1.23)) 
wat: List[Int] = List(true, "hello", 1.23)

@ + 1) 
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Integer
1 Like

Which version of SBT are you using? Is that 1.0? If so, I would try to upgrade to a newer SBT version.

It seems to be sbt 1.3.8. Is that bad?

Hi tpolecat, are you suggesting that the warning are causing the fatal errors in sbt?

You probably need to check/modify your combination of JDK/Scala/sbt.

When I check in my system preferences it seems Java 8 is installed, but when I type java -version at the command line it tells me java 14 is installed. I’ve tried several times to re-install java 8 or java 11, and the command line java from /usr/bin/java always reports java 14. Is that a problem?

Screenshot 2020-04-30 at 14.44.06

@sangamon, this looks like a horrible mess.

Do you know how sbt decides which version of scala to use? As I understand there’s no guarantee that intelliJ and sbt will chose the same version of scala. Right?

Am I correct that it is scala which choses the java version, or is it just the one installed in /usr/bin ?

Usually, you specify the Scala version in the build definition. I guess there would be a default version if you don’t.

The IntelliJ Scala plugin usually uses sbt to create a build definition, so sbt and IntelliJ should be using the same Scala version.

I think we had this conversation several months ago, about how to ask intellij which scala version it is using.

The build.sbt file in my target/ directory indicates scala version 2.12.8, and sbt scalaVersion indicates the same thing.

sbt uses a hardwired Scala version internally (2.12.7 so far, as I understand from the discussion in the bug report), and for your project it uses whatever it has configured. IntelliJ should use the Scala version you have configured in sbt for your project, as well.

I’d guess that both sbt and IntelliJ use the java executable they find on the path - maybe it’s also configurable via cmd line args or env vars (JAVA_HOME), never looked into this.

The easiest remedy probably is to use JDK 11 (which doesn’t seem to be affected and is the current LTS version) and the latest stable sbt version.

so far I’ve been unsuccessful uninstalling java 14 from my system. the recipes I find on stackexchange don’t seem to work.

found a nice recipe here.

Setting the environment variable JAVA_HOME causes /usr/bin/java to use a different version.

csh> brew cask install java
csh> /usr/libexec/java_home -v11
csh> setenv JAVA_HOME `/usr/libexec/java_home -v11`
csh> 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)

After that sbt test no longer dies with error reported above, and I get all tests pass.

yipee, thanks everyone for the help


I have some questions about these unchecked since it is eliminated by erasure warnings in another thread.