0

I'm using the MongoDB Casbah libraries for Scala on a mixed Java/Scala project.

This code works fine in the REPL:

studentCollection.distinct("districtlea").foreach(x => {
 println(x)
 val q = MongoDBObject("districtlea" -> x)
 val studentWithDistrict = studentCollection.findOne(q)
 studentWithDistrict match {
   case Some(s) => println(s.getAs[String]("districtname").getOrElse("NO DISTRICT NAME FOUND FOR LEA " + x))
   case None => println("NO DISTRICT FOUND WITH LEA ")
}
})

When I run it via my Ant build (with the same classpath as the one I use in the REPL), it compiles fine, but I get this at runtime:

 [java] java.lang.VerifyError: (class: scala/collection/immutable/List, method: ms$1 signature: (Lscala/collection/immutable/List;Lscala/Function2;)Lscala/collection/immutable/List;) Incompatible argument to function
 [java]     at scala.sys.SystemProperties$.propertyHelp(SystemProperties.scala:57)
 [java]     at scala.sys.SystemProperties$.addHelp(SystemProperties.scala:59)
 [java]     at scala.sys.SystemProperties$.bool(SystemProperties.scala:63)
 [java]     at scala.sys.SystemProperties$.noTraceSupression(SystemProperties.scala:75)
 [java]     at scala.util.control.NoStackTrace$class.fillInStackTrace(NoStackTrace.scala:21)
 [java]     at scala.util.control.BreakControl.fillInStackTrace(Breaks.scala:77)
 [java]     at java.lang.Throwable.<init>(Throwable.java:181)
 [java]     at scala.util.control.BreakControl.<init>(Breaks.scala:77)
 [java]     at scala.util.control.Breaks.<init>(Breaks.scala:30)
 [java]     at scala.collection.Traversable$.<init>(Traversable.scala:103)
 [java]     at scala.collection.Traversable$.<clinit>(Traversable.scala)
 [java]     at scala.package$.<init>(package.scala:37)
 [java]     at scala.package$.<clinit>(package.scala)
 [java]     at scala.Predef$.<init>(Predef.scala:32)
 [java]     at scala.Predef$.<clinit>(Predef.scala)
 [java]     at com.enspire.hive.elements.pub.SelectionJson$$anonfun$1.apply(SelectionJson.scala:17)
...

The final line of that stack trace points to the "val q = ..." line.

I built the Casbah libraries [2.9.0-1-2.2.0-SNAPSHOT] using Scala 2.9.0-1 and am using the same for running it. I suspect that this error has something to do with some library on the classpath that was built with an incompatible version of Scala, but I can't find it anywhere, and I can't explain why the same code works in the REPL with the same classpath. I'd appreciate any ideas on where to dig further.

brandon
  • 675
  • 6
  • 10

1 Answers1

2

Looks like one of your third party libraries is linked against an old version of Scala:

[java] at com.enspire.hive.elements.pub.SelectionJson$$anonfun$1.apply(SelectionJson.scala:17)

Appears to be the root of the flit down into the wrong linkage.

Brendan W. McAdams
  • 9,379
  • 3
  • 41
  • 31
  • Thanks for the response ... in my attempt to track this down, I've now removed all of the Scala jars from the classpath except the scala-library, the casbah jars, and the minimum set of jars that will get casbah to run (all pulled directly from casbah's sbt lib_managed/scala_2.9.0-1 directory). SelectionJson.scala:17 points to the line `val q = MongoDBObject("districtlea" -> x)`. Any idea where I should keep looking? The next move is to abandon the ant build and switch entirely over to sbt, which wouldn't be bad anyway. – brandon Jul 07 '11 at 19:25
  • Further investigation: the code works with exactly the same classpath if I run it via JUnit, either via Ant or directly. I now suspect that the problem lies with the fact that the Java project I'm using this with uses a custom classloader to facilitate bytecode instrumentation of certain java classes. It doesn't have anything to do with Scala, so I'm still not sure why it would cause this error, but that is the only difference that I can ascertain. We've moved past this problem now, but when I get time, I'm going to track this down just to learn what's happening. – brandon Jul 08 '11 at 16:37
  • Ya, the stacktrace you are showing is definitely not Casbah related; we absolutely never use Break or BreakControl in Casbah as well. – Brendan W. McAdams Jul 10 '11 at 16:13