-
Notifications
You must be signed in to change notification settings - Fork 21
Serialization of static modules does not need to contain any data #10412
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
Comments
nice catch |
(It was some else's 🎣 ) |
@lrytz I'm reassigning most 2.12.5 tickets to "Backlog", but this seems like it might be low-hanging fruit you might actually like to tackle for 2.12.5 or 2.12.6? |
The problem gets worse when the object contains non-serializable state or when you use serialization proxies and circular dependencies (in which case a proxy of the wrong type can leak out into other deserialization code). There does not seem to be an easy way to avoid this problem in a generic way (i.e. in a trait which could be implemented by multiple objects). It can't extend private[this] def writeObject(out: ObjectOutputStream): Unit = ()
private[this] def readObject(in: ObjectInputStream): Unit = () A proper fix could consist of giving module classes a public constructor and implementing |
Hmm, I just merged scala/scala#6676 which adds a number of these overrides that @szeiger suggests above. However, reading https://docs.oracle.com/javase/8/docs/platform/serialization/spec/output.html#a861
Maybe we're fine because modules have a For superclasses of modules, this is not the case; they don't have a |
I also read that section before making the change. Continuing in the same paragraph:
Maybe I don't understand the implications but this looks to me like it is perfectly safe not do do default serialization. What's the point of deserializing an object when the class cannot be resolved? The only use case appears to be partial parsing of object streams, i.e. skipping over objects that cannot be deserialized. Maybe deserializing with a new, not binary compatible, version of a class that omits a superclass? Since we don't even guarantee serialization compatibility for binary compatible classes we can ignore this case.
Note that The best we can safely do is to not serialize the object's own state. If we implement this directly in the compiler, an alternative to Another alternative that would prevent serialization of superclass state is to automatically implement |
Cant this simple be fixed with writeReplace/readResolve, that the normal way to do singleton serialisation,
so we generate in the static module
and a utility class
|
@szeiger What problems are you thinking about when you say:
|
I was referring to the cyclic references problem with serialization proxies but a quick test run of serialization tests for the collections (with my current workaround replaced by a proxy) shows no problems. I'll have to perform a broader test by letting the compiler generate this pattern for all singleton objects. |
Here's my attempt so far: scala/scala@2.13.x...szeiger:issue/10412 But I can't make it work. Whatever way I use to generate the call to
Any suggestions welcome on how to do that adaptation to the existential type correctly. |
(scala/scala#7297 replaced scala/scala#6877) |
Static modules get a
readResolve
method that returns the singleton instance, so the de-serialized object is not used. So there's no need to serialize all the fields. See also #9375.The text was updated successfully, but these errors were encountered: