-
Notifications
You must be signed in to change notification settings - Fork 21
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
Simply extending Iterable would break on Java serialization #11192
Comments
This comment has been minimized.
This comment has been minimized.
* Upgrade to Scala 2.13.0-M5 * Upgrade ScalaTest and Scalacheck * Update travis config for Scala 2.13.0-M5 * Scala 2.13.0-M5 confused java.util.logging.LogRecord and wvlet.log.LogRecord * Fix scala/bug#11202 by explicitely specifying JMX annotation package path * Use Scala test 3.0.6-SNAP4 * Add a workaround for Scala 2.13.0-M5 serialization bug: scala/bug#11192 * Exclude airframe-fluentd from Scala 2.13 build * Exclude serilaization test for Scala 2.13.0-M5 instead of forking JVM
I think the current behavior fits well into the collections design and should be considered correct. Deserialization will deserialize to the |
We can make the new serialization scheme opt-in by putting it into a mix-in trait for the concrete collection types. This leaves serialization undefined by default, which was the case in 2.12. (Note that simply extending Iterable would not have worked in 2.12, either, because Iterable is not Serializable) |
If it fails at serialization as opposed to deserialization, that would be a safer failure mode. |
This is a generalization of scala/scala-xml#254 reported by @ashawley and analyzed by @xuwei-k
steps
To minimize
scala.xml.XMLTestJVM.serializeAttribute
failure Yoshida-san created a minimization using a custom collection that looks like this:I'm breaking up the test into the following steps:
problem
When I run this the error I get is as follows:
In other words, I don't get to the assertion, but instead it's failing at casting in the deserialization which deserialized
$colon$colon
instead ofMyCollection
. This looks to be a different problem than #9237.expectation
Either the serialization works out of the box, or
MyCollection
does not compile without providing some serialization mechanism.workaround
A workaround identified by Yoshida-san is uncommenting the following:
// protected[this] override def writeReplace(): AnyRef = this
note
scala/scala#6676 makes
Iterable
Serializable by default.with
writeReplace
implemented as follows:In other words, the serialization of all things Iterable are passed into
DefaultSerializationProxy
, including all subtypes that exist in the wild. Perhaps it should fail at the point of serialization when it detects a type that it cannot handle.Letting it serialize the data, but not deserialize sounds like a potentially data-losing behavior. Another thing to consider is forcing subclasses of
Iterable
to implement a serialization method. The situation where it's easy to roll your own collection, but it will blow up on Spark by default is not a happy experience.The text was updated successfully, but these errors were encountered: