2

I have a case where I'm pickling an object where a ref is repeated inside an object tree. I am getting an invalid index exception when unpickling. Below is a test case.

import scala.pickling._
import json._
object JsonTest extends App {
  val obj = StringProp("test")
  val pickle = new PropTest(obj, obj).pickle.unpickle[PropTest]
}
case class StringProp(prop: String) {}
class PropTest(val prop1: StringProp, val prop2: StringProp) {}

Thanks in advance for taking a look at this.

Here is the stacktrace of the error:

Exception in thread "main" java.lang.Error: fatal error: invalid index 1 in unpicklee cache of length 1
    at scala.pickling.internal.package$.lookupUnpicklee(package.scala:151)
    at scala.pickling.json.JSONPickleReader$$anonfun$30.apply(JSONPickleFormat.scala:163)
    at scala.pickling.json.JSONPickleReader.readPrimitive(JSONPickleFormat.scala:229)
    at scala.pickling.CorePicklersUnpicklers$PrimitivePicklerUnpickler.unpickle(Custom.scala:313)
    at com.ft.flexui.modules.pm.JsonTest$ComFtFlexuiModulesPmPropTestUnpickler2$2$.unpickle(JsonTest.scala:135)
    at com.ft.flexui.modules.pm.JsonTest$delayedInit$body.apply(JsonTest.scala:135)
    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:71)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
    at scala.App$class.main(App.scala:71)
    at com.ft.flexui.modules.pm.JsonTest$.main(JsonTest.scala:13)
    at com.ft.flexui.modules.pm.JsonTest.main(JsonTest.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
kevin z
  • 75
  • 3

1 Answers1

0

See scala/pickling#240 for the details.

So it looks like it attempting to create a pointer to the object as a form of compression but gets confused.

And Heather confirms:

somehow something is misbehaving when we generate this code to analyze object graphs at runtime.

The workaround for now is:

import scala.pickling.shareNothing._
Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319