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?

5
  • You have a method in TokenHandler called lines? Commented Aug 6, 2019 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. Commented Aug 6, 2019 at 17:00
  • @PedroCorreiaLuís no, no methods called lines. At some point, my method verify() does call a third-party library, java-jwt, but even there I wasn't able to find any call to lines... Commented Aug 7, 2019 at 7:54
  • Verify is a method of yours? because ScalaMock also has a method called verify, maybe you are calling the wrong method. Commented Aug 7, 2019 at 9: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 :/ Commented Aug 7, 2019 at 10:58

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

3 Comments

It works correctly with ScalaMock version 4.4.0-SNAPSHOT. Thanks!
awesome. i'll release 4.4.0 proper this weekend then, thanks for testing it :)
pushed 4.4.0 to maven central. it's syncing up now
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.