[concurrency-interest] subList, subMap and navigable

Doug Lea dl at cs.oswego.edu
Mon Jul 23 12:20:18 EDT 2012


On 07/23/12 10:27, Stanimir Simeonoff wrote:
> It looks subMaps returned by the implementers of SortedMap are serializable as
> rule of the thumb. All subLists returned by COWArrayList, ArrayList, LinkedList,
> etc are not.

The reason for not serializing views (sub{Set/List/Map},
Map.keySet(), etc) is given in

> While I realize  it's an official bug:
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4782922

There is no way to serialize a view without serializing the
full backing source. Doing so violates all reasonable expectations
about what serialization should do. So the Serialization exception
is telling you to first store the view in an actual collection/map,
and serialize that.

This has been a general (although under-explained) policy
ever since the introduction of Collections. But there
are a few classes that don't follow it.

-Doug


More information about the Concurrency-interest mailing list