pickling
pickling copied to clipboard
Check validity of hints
object PicklingTest extends App {
import scala.pickling.Defaults._
import scala.pickling.json._
case class X(i: Int)
implicit val shitPickler: Pickler[X] = new Pickler[X] {
override val tag = FastTypeTag[X]
override def pickle(x: X, builder: PBuilder): Unit = {
builder.beginEntry(x)
AllPicklers.intPickler.pickle(x.i, builder)
builder.endEntry()
}
}
val s = X(5)
println(s.pickle)
}
Results in:
Exception in thread "main" java.lang.NullPointerException
at scala.pickling.json.JSONPickleBuilder$$anonfun$beginEntry$1.apply(JSONPickleFormat.scala:109)
at scala.pickling.json.JSONPickleBuilder$$anonfun$beginEntry$1.apply(JSONPickleFormat.scala:102)
at scala.pickling.PickleTools$class.withHints(Tools.scala:521)
at scala.pickling.json.JSONPickleBuilder.withHints(JSONPickleFormat.scala:39)
at scala.pickling.json.JSONPickleBuilder.beginEntry(JSONPickleFormat.scala:102)
at scala.pickling.pickler.PrimitivePickler.pickle(Primitives.scala:23)
at test.pickling.PicklingTest$$anon$8.pickle(PicklingTest.scala:25)
at test.pickling.PicklingTest$$anon$8.pickle(PicklingTest.scala:21)
at scala.pickling.functions$.pickleInto(functions.scala:36)
at scala.pickling.functions$.pickle(functions.scala:19)
at scala.pickling.PickleOps.pickle(Ops.scala:9)
at test.pickling.PicklingTest$.delayedEndpoint$test$pickling$PicklingTest$1(PicklingTest.scala:30)
at test.pickling.PicklingTest$delayedInit$body.apply(PicklingTest.scala:10)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:381)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.App$class.main(App.scala:76)
at test.pickling.PicklingTest$.main(PicklingTest.scala:10)
at test.pickling.PicklingTest.main(PicklingTest.scala)
It should give an explanation what went wrong and how to fix the problem.
These two methods are broken:
trait PickleTools {
def popHints(): this.type = {
hints = hints.tail
this
}
def withHints[T](body: Hints => T): T = {
val hints = this.hints.head
if (!hints.pinned) this.hints = Hints() :: this.hints.tail
body(hints)
}
}
popHints can't pop infinitely and withHints need to check if hints.tag is not null.
@sschaef Two things:
- hintTag is no longer option, and is now included in
beginEntryfor a pickler. That should help solve the first issue. - push/pop hints may need some lovin/fixing soon. Would like to suggestions on how to fix.