Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6242436

(coll) TreeMap.SubMap doesn't deserialize properly

XMLWordPrintable

    • b51
    • x86
    • windows_xp
    • Verified

      FULL PRODUCT VERSION :
      java version "1.5.0_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
      Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP Professional
      Build 2600.xpsp2.030422-1633 (Service pack 1)

      A DESCRIPTION OF THE PROBLEM :
      After serializing/deserializing java.util.TreeMap$SubMap calling the entrySet() method on the resulting Map always returns null.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      serialize/deserialize instance of java.util.TreeMap$SubMap and attempt to use it (could be as simple as using it as an argument with RMI).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Same functionallity as before serialization/deserialization
      ACTUAL -
      java.lang.NullPointerException


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      C:\>java SubmapSerializeTest
      {key0=value0, key1=value1, key2=value2, key3=value3, key4=value4, key5=value5, k
      ey6=value6, key7=value7, key8=value8, key9=value9}
      {key2=value2, key3=value3, key4=value4, key5=value5, key6=value6, key7=value7}
      java.lang.NullPointerException
              at java.util.AbstractMap.toString(AbstractMap.java:584)
              at java.lang.String.valueOf(String.java:2577)
              at java.io.PrintStream.print(PrintStream.java:616)
              at java.io.PrintStream.println(PrintStream.java:753)
              at SubmapSerializeTest.main(SubmapSerializeTest.java:25)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      import java.util.*;

      public class SubmapSerializeTest {

          public static void main(String[] args) {
              try {
                  SortedMap map = new TreeMap();
                  for (int i = 0; i < 10; i++) {
                      map.put("key" + i, "value" + i);
                  }
                  System.out.println(map);

                  ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);
                  ObjectOutputStream out = new ObjectOutputStream(outputStream);
                  SortedMap serializedMap = map.subMap("key2", "key8");
                  out.writeObject(serializedMap);
                  out.close();
                  System.out.println(serializedMap);

                  byte[] byteArray = outputStream.toByteArray();
                  InputStream inputStream = new ByteArrayInputStream(byteArray);
                  ObjectInputStream in = new ObjectInputStream(inputStream);
                  SortedMap deserializedMap = (SortedMap) in.readObject();
                  System.out.println(deserializedMap);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Create a new TreeMap with all the entries from the subMap before serialization
      ###@###.### 2005-03-17 21:31:31 GMT

            martin Martin Buchholz
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: