Hi Sergey, Michael might correct me if I’ve missed something, but problem with your test case is that you’re serializing already patched version. That makes sense if you want to test current behavior. However the case you truly want to test is how your patched TreeMap deserializes pre-patched TreeMaps.
What you have currently just tests if patched map could be deserialized without any problems. Cheers, su - On Wed, 5 Sep 2018 at 20:30, Сергей Цыпанов <sergei.tsypa...@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 >