[concurrency-interest] subList, subMap and navigable

Stanimir Simeonoff stanimir at riflexo.com
Mon Jul 23 15:16:16 EDT 2012

> I'm not sure why this was done. My fuzzy recollection is that
> TreeMap initially did do for some reason, and CSLM did the same
> to maintain pluggability. But in general, you can't count on
> serializability of views.
> I have subclasses ObjectOutputStream and implemented replaceObject to
handle not serializable views by returning a serializable one but that is a
true hack.

Imagine the case
  void process(java.util.List)
If the code is invoked locally it just works and not copy but supplying the
view is potentially more performance friendly. Receiving an interface that
will be invoked through some form of RPC (rmi included) breaks with
NotSerializableException. It's an IOException and unless handled separately
(ObjectStreamException) it is quite the same as broken connection, speaking
too broadly.
The real-world case was removing the first element of the list but instead
of copying it a subList was used.Not serializing also partly breaks the doc
contract: *"Any operation that expects list can be used as a range
operation by passing a subList view instead of a whole list"*
I do not expect the bug/RFE to be reopen but probably docs should reflect
the case.

btw, TreeSet.subSet() is also serializable - the subSet is just another
TreeSet [return new TreeSet<E>(m.subMap(fromElement,
fromInclusive,toElement,   toInclusive));]
Also TreeSet.writeObject follows the pattern to write the objects one by
one and on readObject creates a new TreeMap and fills it back -- so
definitely serializes only the part being viewed.
So the main offender is the subList which worsen the case - given the
TreeSet example, it's possible w/o breaking anything to be implemented for

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20120723/4af00a13/attachment.html>

More information about the Concurrency-interest mailing list