5

I'm running into a weird error when using Spark and Scala. I have a piece of code that declares a variable:

var offset = 0

This causes the following exception:

java.lang.NoSuchMethodError: scala.runtime.IntRef.create(I)Lscala/runtime/IntRef;
   at my.package.MyClass$class.myMethod(MyClass.scala:5)
   ...

And it points directly at the variable declaration. I am using Scala 2.11.2. Compiling works. This is a runtime error. I do not get any dependency/version mismatch warnings when running sbt package either.

tolgap
  • 9,629
  • 10
  • 51
  • 65
  • This is almost certainly a scala version mismatch. Comparing the definition of `IntRef` in v2.10 and v2.11, you can see that `create` was only introduced in the latter version (see https://github.com/scala/scala/blob/v2.10.4/src/library/scala/runtime/IntRef.java and https://github.com/scala/scala/blob/v2.11.0/src/library/scala/runtime/IntRef.java). You can bet that some of your dependencies was compiled against a scala version < 2.11.0. You muight want to try sbt-dependency-graph (https://github.com/jrudolph/sbt-dependency-graph) to check your transitive dependencies. – Régis Jean-Gilles Jan 13 '15 at 15:53
  • Yeah you were right Règis. I changed my Scala version to 2.10.4 and it started working as expected. You can put your comment as an answer and I'll accept it. – tolgap Jan 13 '15 at 15:54

1 Answers1

12

This is almost certainly a scala version mismatch. Comparing the definition of IntRef in v2.10 and v2.11, you can see that create was only introduced in the latter version (see https://github.com/scala/scala/blob/v2.10.4/src/library/scala/runtime/IntRef.java and https://github.com/scala/scala/blob/v2.11.0/src/library/scala/runtime/IntRef.java). You can bet that some of your dependencies was compiled against a scala version < 2.11.0. You might want to try sbt-dependency-graph (https://github.com/jrudolph/sbt-dependency-graph) to check your transitive dependencies.

Régis Jean-Gilles
  • 32,541
  • 5
  • 83
  • 97