[concurrency-interest] subList, subMap and navigable

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


.

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


But subMaps are serializable for instance:
TreeMap:: NavigableSubMap<K,V> extends AbstractMap<K,V>
        implements NavigableMap<K,V>, java.io.Serializable {
}
AscendingSubMap extends NavigableSubMap has even serialVersionUID.

ConcurrentSkipListMap::    static final class SubMap<K,V> extends
AbstractMap<K,V>
        implements ConcurrentNavigableMap<K,V>, Cloneable,
                   java.io.Serializable {
private static final long serialVersionUID = -7647078645895051609L;
...
}

That's the greatest part of the confusion: TreeMap.subMap returns a
serializable view and when serialized it does serialize the real map -
pretty much expected behavior, it reasoning in the bug applies just as well
on Maps, not just Collecions. It's possible to use writeReplace and create
the same case TreeMap.subMap - so the class is the same would work via
readResolve. ConcurrentSkipListMap is no different - it also returns
serializeable subMaps.
None of maps' collection views are serializable though - which is
consistent with the fact that collection views are not serializable.

Btw, any insight on the 2nd question about the introduction of Navigable?

Thanks again
Stanimir

While I realize  it's an official bug:
>> http://bugs.sun.com/**bugdatabase/view_bug.do?bug_**id=4782922<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
>
> ______________________________**_________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.**oswego.edu <Concurrency-interest at cs.oswego.edu>
> http://cs.oswego.edu/mailman/**listinfo/concurrency-interest<http://cs.oswego.edu/mailman/listinfo/concurrency-interest>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20120723/b9393f0d/attachment.html>


More information about the Concurrency-interest mailing list