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

IdentityHashMap serialize size value incorrectly

XMLWordPrintable



      Name: ygR10224 Date: 02/20/2003


          The number of key-value mappings of java.util.IdentityHashMap
          (which returns by size() method) are different before and
          after serialization.
          
          See below for an example that reproduces this bug:
          -------------------- Test.java ----------------------
          import java.util.*;
          import java.io.*;

          public class Test {
              public static void main(String[] args) throws Exception {
                  IdentityHashMap obj = new IdentityHashMap();
                  obj.put("dummykey1", "dummyvalue1");
                  obj.put("dummykey2", "dummyvalue2");
                  obj.put("dummykey3", "dummyvalue3");

                  FileOutputStream fos = new FileOutputStream("test.ser");
                  ObjectOutputStream oos = new ObjectOutputStream(fos);
                  oos.writeObject(obj);
                  oos.flush();
                  oos.close();

                  FileInputStream fis = new FileInputStream("test.ser");
                  ObjectInputStream ois = new ObjectInputStream(fis);
                  IdentityHashMap nobj = (IdentityHashMap) ois.readObject();
                  ois.close();

                  if (obj.size() == nobj.size()) {
                      System.out.println("PASSED");
                  } else {
                      System.out.println("FAILED");
                      System.out.println("\"size\" value before and after " +
                              "serialization not equal (" + obj.size() + " != " +
                              nobj.size() + ").");
                  }
              }
          }
          ------------------- example output ------------------
          java -showversion Test
          java version "1.4.2-beta"
          Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b16)
          Java HotSpot(TM) Client VM (build 1.4.2-beta-b16, mixed mode)

          FAILED
          "size" value before and after serialization not equal (3 != 6).
          ------------------- end of output -------------------
      ======================================================================

            jjb Josh Bloch
            gyisunw Gyi Gyi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: