You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to deserialize a case class that contains a Scala collection (e.g., Seq, Vector) of case objects, java.io.ObjectInputStream throws an error Cannot assign instance of scala.collection.generic.DefaultSerializationProxy to field to ....
How to reproduce
build.sbt
scalaVersion := "2.13.0-M5"
// fork in run := true // uncomment this to resolve this error
sealedtraitColorcaseobjectREDextendsColorcaseclassA(colors:Seq[Color]) // Deserialization of A fails
$ sbt run
[info] Running serde.SerdeTest
[error] (run-main-14) java.lang.ClassCastException: cannot assign instance of scala.collection.generic.DefaultSerializationProxy to field serde.A.colors of type scala.collection.immutable.Seq in instance of serde.A
[error] java.lang.ClassCastException: cannot assign instance of scala.collection.generic.DefaultSerializationProxy to field serde.A.colors of type scala.collection.immutable.Seq in instance of serde.A
[error] at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(ObjectStreamClass.java:2287)
[error] at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:1417)
[error] at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2293)
[error] at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2211)
[error] at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2069)
[error] at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1573)
[error] at java.io.ObjectInputStream.readObject(ObjectInputStream.java:431)
[error] at serde.SerdeTest$.deserialize(SerdeTest.scala:22)
[error] at serde.SerdeTest$.main(SerdeTest.scala:29)
[error] at serde.SerdeTest.main(SerdeTest.scala)
[error] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] at java.lang.reflect.Method.invoke(Method.java:498)
[error] Nonzero exit code: 1
[error] (Compile / run) Nonzero exit code: 1
The text was updated successfully, but these errors were encountered:
xerial
changed the title
Cannot assign instance of scala.collection.generic.DefaultSerializationProxy in Scala 2.13.0-M5
Cannot deserialize scala.collection.generic.DefaultSerializationProxy in Scala 2.13.0-M5
Oct 12, 2018
This appears to be a different symptom of the same root cause.
ObjectInputStream encounters an java.lang.ClassNotFoundException: serde.RED$, which it records internally for later reporting.
This seems to prevent the use of the readResolve method:
/** * If resolveObject has been enabled and given object does not have an * exception associated with it, calls resolveObject to determine * replacement for object, and updates handle table accordingly. Returns * replacement object, or echoes provided object if no replacement * occurred. Expects that passHandle is set to given object's handle prior * to calling this method. */privateObjectcheckResolve(Objectobj) throwsIOException {
if (!enableResolve || handles.lookupException(passHandle) != null) {
returnobj;
}
Objectrep = resolveObject(obj);
Which leads to the ClassCastException obscuring the root cause.
When trying to deserialize a case class that contains a Scala collection (e.g., Seq, Vector) of case objects, java.io.ObjectInputStream throws an error
Cannot assign instance of scala.collection.generic.DefaultSerializationProxy to field to ...
.How to reproduce
build.sbt
SerdeTest.scala
https://gist.github.com/xerial/58e14b21a4492d6f87765fe9bff4b61a
Related issues:
The text was updated successfully, but these errors were encountered: