Skip to content

Instantly share code, notes, and snippets.

@raronson
Created March 3, 2014 11:36
Show Gist options
  • Save raronson/9323255 to your computer and use it in GitHub Desktop.
Save raronson/9323255 to your computer and use it in GitHub Desktop.
spec to replicate java.lang.ClassCastException: scalaz.$minus$bslash$div cannot be cast to java.lang.String
package com.ambiata.ivory.scoobi
import org.specs2._
import com.nicta.scoobi.Scoobi._
import com.nicta.scoobi.testing.mutable._
import com.nicta.scoobi.testing.SimpleJobs
import com.nicta.scoobi.testing.TestFiles._
import com.nicta.scoobi.testing.TempFiles
import scalaz.{DList => _, _}, Scalaz._
object ScalazWireFormats {
import java.io._
implicit def ValidationFmt[A, B](implicit awf: WireFormat[A], bwf: WireFormat[B]) = new WireFormat[Validation[A, B]] {
def toWire(v: Validation[A, B], out: DataOutput) = {
v match {
case Failure(a) => { out.writeBoolean(false); awf.toWire(a, out) }
case Success(b) => { out.writeBoolean(true); bwf.toWire(b, out) }
}
}
def fromWire(in: DataInput): Validation[A, B] = {
in.readBoolean match {
case false => awf.fromWire(in).failure
case true => bwf.fromWire(in).success
}
}
def show(v: Validation[A, B]): String = v.toString
}
implicit def DisjunctionFmt[A, B](implicit wf: WireFormat[Either[A, B]]) = new WireFormat[A \/ B] {
def toWire(v: A \/ B, out: DataOutput) = wf.toWire(v.toEither, out)
def fromWire(in: DataInput): A \/ B = wf.fromWire(in).disjunction
def show(v: A \/ B): String = v.toString
}
}
/**
* Run with -- scoobi verbose.all to see class cast exception
*/
class BugSpec extends HadoopSpecification with SimpleJobs {
import ScalazWireFormats._
"Should not get class cast exception" >> { implicit sc: ScoobiConfiguration =>
val dlist: DList[String \/ Int] = DList("test".left, 1.right)
val lefts: DList[String] = dlist.collect {
case -\/(l) => l
}
val rights: DList[Int] = dlist.collect {
case \/-(r) => r
}
val other: DList[String \/ Int] = rights.map(_.toString.left)
val otherLefts = other collect {
case -\/(l) => l
}
val all = (lefts ++ otherLefts)
val len = all.length
persist(len, all.toTextFile(path(TempFiles.createTempDir("bug").getPath)))
len.run must_== 2
}
}
@ChongTang
Copy link

Same here. Did you find a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment