[PATCH] Simplification of TreeMap

Martin Buchholz martinrb at google.com
Wed Sep 5 19:13:46 UTC 2018


Сергей, they say "If it ain't broke, don't fix it".  Your implementation is
indeed more maintainable, but TreeMap has been rather stable and is
unlikely to see much maintenance!  (unless value types makes it compelling).

One of many problems with serialization is that cross-version compatibility
is hard to test and so usually ends up untested.

On Wed, Sep 5, 2018 at 11:30 AM, Сергей Цыпанов <sergei.tsypanov at yandex.ru>
wrote:

> Hi Michael,
>
> thanks for pointing out this serialization concern, I didn't think about
> it at all.
>
> I've wrote a simple test for serialization of patched TreeMap and it works
> without errors for both no-args constructor and constructor with comparator:
>
> public class TreeMapSerialization {
>     public static void main(String[] args) throws Exception {
>         TreeMap<Integer, String> serialized = new TreeMap<>(Comparator.
> reverseOrder());
>         serialized.put(1, "1");
>         serialized.put(2, "2");
>
>         ByteArrayOutputStream baos = new ByteArrayOutputStream();
>         ObjectOutputStream oos = new ObjectOutputStream(baos);
>
>         oos.writeObject(serialized);
>         oos.flush();
>         baos.flush();
>         oos.close();
>         baos.close();
>
>         ByteArrayInputStream bais = new ByteArrayInputStream(baos.
> toByteArray());
>         ObjectInputStream ois = new ObjectInputStream(bais);
>
>         TreeMap<Integer, String> deserialized = (TreeMap<Integer, String>)
> ois.readObject();
>         deserialized.put(3, "3");
>
>         System.out.println(deserialized);
>     }
> }
>
>
> I hope I don't miss anything, so there shouldn't be any serialization
> issues.
>
> Regards,
> Sergey Tsypanov
>


More information about the core-libs-dev mailing list