2013-10-17 34 views
2

我有一個案例,我正在酸洗一個對象,其中ref在對象樹中重複。取出時我得到一個無效的索引異常。以下是一個測試案例。重複對象引用的索引取消無效

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) {} 

在此先感謝您看看這個。

以下是錯誤的堆棧跟蹤:

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) 

回答

0

scala/pickling#240的細節。

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

和希瑟證實:

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

現在的解決方法是:

import scala.pickling.shareNothing._ 
相關問題