Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot deserialize scala.collection.generic.DefaultSerializationProxy in Scala 2.13.0-M5 #11204

Closed
xerial opened this issue Oct 12, 2018 · 2 comments

Comments

@xerial
Copy link

xerial commented Oct 12, 2018

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

SerdeTest.scala
https://gist.github.com/xerial/58e14b21a4492d6f87765fe9bff4b61a

sealed trait Color
case object RED extends Color
case class A(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

Related issues:

@xerial 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
@xuwei-k xuwei-k added this to the 2.13.0-RC1 milestone Oct 13, 2018
@retronym
Copy link
Member

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.
     */
    private Object checkResolve(Object obj) throws IOException {
        if (!enableResolve || handles.lookupException(passHandle) != null) {
            return obj;
        }
        Object rep = resolveObject(obj);

Which leads to the ClassCastException obscuring the root cause.

@szeiger
Copy link

szeiger commented Jan 8, 2019

Closing as duplicate of #9237

@szeiger szeiger closed this as completed Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants