1

I'm using ScalaTest and ScalaMock and I run into an exception preventing my test to even run.

An exception or error caused a run to abort:
java.lang.String.lines()Ljava/util/stream/Stream;

I'm using Scala 2.13, JDK 8 and the latest versions of the frameworks: ScalaTest 3.0.8 and ScalaMock 4.3.0.

My usage of the mocking framework is something like:

import org.scalamock.scalatest.MockFactory

class AcceptanceTest extends MockFactory {
  val tokenHandler = mock[TokenHandler]
  tokenHandler.verify()
}

I'm not explicitly invoking the method lines(), nor I have found it invoked by verify(). The problem only comes if I call verify() though.

This is the stacktrace of the error:

java.lang.NoSuchMethodError: java.lang.String.lines()Ljava/util/stream/Stream;
    at org.scalamock.handlers.Handlers$$anonfun$toString$1.apply(Handlers.scala:35)
    at org.scalamock.handlers.Handlers$$anonfun$toString$1.apply(Handlers.scala:34)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
    at scala.collection.immutable.List.foreach(List.scala:392)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
    at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:45)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
    at scala.collection.AbstractTraversable.map(Traversable.scala:104)
    at org.scalamock.handlers.Handlers.toString(Handlers.scala:34)
    at java.lang.String.valueOf(String.java:2994)
    at java.lang.StringBuilder.append(StringBuilder.java:131)
    at scala.StringContext.standardInterpolator(StringContext.scala:125)
    at scala.StringContext.s(StringContext.scala:95)
    at org.scalamock.context.MockContext$class.errorContext(MockContext.scala:48)
...
    at org.scalatest.tools.SuiteRunner.run(SuiteRunner.scala:45)
    at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$1.apply(Runner.scala:1349)
    at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$1.apply(Runner.scala:1343)
    at scala.collection.immutable.List.foreach(List.scala:392)
    at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:1343)
    at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1012)
    at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1011)
    at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1509)
    at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1011)
    at org.scalatest.tools.Runner$.run(Runner.scala:850)
    at org.scalatest.tools.Runner.run(Runner.scala)

Any idea on how to get rid of it?

poffuomo
  • 11
  • 1
  • 5
  • You have a method in TokenHandler called lines? – Pedro Correia Luís Aug 06 '19 at 16:45
  • 2
    this looks like a symptom of compiling code on JDK 11 but then running the compiled code on JDK 8. in JDK 11, `java.lang.String` has a `lines` method, but on JDK 8 it doesn't. – Seth Tisue Aug 06 '19 at 17:00
  • @PedroCorreiaLuís no, no methods called `lines`. At some point, my method `verify()` does call a third-party library, [java-jwt](https://github.com/auth0/java-jwt), but even there I wasn't able to find any call to `lines`... – poffuomo Aug 07 '19 at 07:54
  • Verify is a method of yours? because ScalaMock also has a method called verify, maybe you are calling the wrong method. – Pedro Correia Luís Aug 07 '19 at 09:08
  • @SethTisue I run my code both on my machine and in Travis by specifying the appropriate JDK version (8). It may be an explanation, but I don't know how that could happen :/ @PedroCorreiaLuís yes, `verify` is a method of mine. I also tried calling an alternative method from the same class, i.e. `verifyToMap`, and got the same error. The ScalaDoc for ScalaMock doesn't show any method with such name :/ – poffuomo Aug 07 '19 at 10:58

2 Answers2

2

The issue is that JDK 11 has a method with the same signature that takes precedence over some implicit. Could you try if using a snapshot version fixes this problem for you? Happy to drop another release ASAP then. See this on how to add Sonatype as a resolver: https://scalamock.org/user-guide/installation/ Give 4.4.0-SNAPSHOT a try please

Philipp
  • 967
  • 6
  • 16
1

This is a bug in ScalaMock itself. The bug report is at https://github.com/paulbutcher/ScalaMock/issues/268

The bug has been fixed, but as of today (August 8, 2019), there isn't yet a new release with the fix.

Seth Tisue
  • 29,985
  • 11
  • 82
  • 149