RFR(m): 8139233 add initial compact immutable collection implementations
Stuart Marks
stuart.marks at oracle.com
Thu May 5 00:21:12 UTC 2016
Hi Daniel,
On 5/4/16 3:08 AM, Daniel Fuchs wrote:
> I wonder about serial interoperability with earlier
> versions of the JDK. For instance it will not be possible to
> send a Set created with Set.of(...) in JDK 9 to a JDK 8 VM.
> I wonder if there is any good solution to that.
> You could of course use writeReplace() to return a plain
> HashSet - but then you would only get a plain HashSet on
> the other end. That might be fine if that other end
> is JDK 8, but maybe not so good if it's actually JDK 9.
Right, in general, you can't serialize a "new" class in a JDK release and
deserialize it on an older JDK. If backward serialization compatibility were a
goal, one could serialize them as a HashSet within an unmodifiable wrapper. But
yes, deserializing that would increase the space consumption considerably.
> What worries me is that it will be very easy to forget about
> the serial incompatibility, and start using these new factory
> methods in e.g. java.lang.management, and then discover later
> on that it has introduced an interoperability issue.
>
> Is there any good way to prevent that - except thorough code
> reviews?
Well I think you'd need to have some kind of interoperability tests. The most
straightforward way to do this would be to keep old versions of the system
around and test them against each other. This is tedious to set up and maintain
and automate though. Maybe you could have some kind of serialization scanner
that takes some serialized data and scans the serialized classes to make sure
they're all in the expected set. But ultimately, if you're sending data that old
versions need to process, you need to keep a close eye on everything that's
serialized. The convenience of being able to serialize an entire object graph
automatically works against you here.
s'marks
More information about the core-libs-dev
mailing list