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

(coll) Should Hashtable collection views be Serializable?

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.3.1, 5.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

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


      ADDITIONAL OS VERSION INFORMATION :
      Linux tsang 2.6.8-1.521 #1 Mon Aug 16 09:01:18 EDT 2004 i686 i686 i386 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      (Hashtable.values() instanceof Serializable) returns true, but Hashtable.values() is not Serialiable

      (Hashtable.keySet() instanceof Serializable) returns true, but Hashtable.keySet() is not Serialiable

      (Hashtable.entrySet() instanceof Serializable) returns true, but Hashtable.entrySet() is not Serialiable

      And the javadoc does not metioned that they are not Serializable

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      (Hashtable.values() instanceof Serializable) should returns false

      (Hashtable.keySet() instanceof Serializable) should returns false

      (Hashtable.entrySet() instanceof Serializable) should returns false

      the javadoc should metion that keys(), values(), keySet(), and entrySet() from Hashtable is not Serializable

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.Hashtable;
      import java.util.Collection;
      import java.util.Enumeration;
      import java.util.Set;
      import java.io.Serializable;
      import java.io.FileOutputStream;
      import java.io.ObjectOutputStream;

      public class TestSerializable {

         public static void main(String[] args) throws java.io.IOException {
            Hashtable h = new Hashtable();
            h.put("a", "aaaaa");

            Collection c = h.values();
            if (c instanceof Serializable)
               System.out.println("... h.values(), yes");
            else
               System.out.println("... h.values(), no");
            try {
               FileOutputStream fos = new FileOutputStream("/tmp/o.tmp");
               ObjectOutputStream oos = new ObjectOutputStream(fos);
               oos.writeObject(c);
               oos.close();
            } catch (Exception e) {
               System.out.println("...... h.values()");
               e.printStackTrace();
            }

            Enumeration en = h.keys();
            if (en instanceof Serializable)
               System.out.println("... h.keys(), yes");
            else
               System.out.println("... h.keys(), no");
            try {
               FileOutputStream fos = new FileOutputStream("/tmp/o.tmp");
               ObjectOutputStream oos = new ObjectOutputStream(fos);
               oos.writeObject(en);
               oos.close();
            } catch (Exception e) {
               System.out.println("...... h.keys()");
               e.printStackTrace();
            }

            Set s = h.keySet();
            if (s instanceof Serializable)
               System.out.println("... h.keySet(), yes");
            else
               System.out.println("... h.keySet(), no");
            try {
               FileOutputStream fos = new FileOutputStream("/tmp/o.tmp");
               ObjectOutputStream oos = new ObjectOutputStream(fos);
               oos.writeObject(s);
               oos.close();
            } catch (Exception e) {
               System.out.println("...... h.keySet()");
               e.printStackTrace();
            }

            s = h.entrySet();
            if (s instanceof Serializable)
               System.out.println("... h.entrySet(), yes");
            else
               System.out.println("... h.entrySet(), no");
            try {
               FileOutputStream fos = new FileOutputStream("/tmp/o.tmp");
               ObjectOutputStream oos = new ObjectOutputStream(fos);
               oos.writeObject(s);
               oos.close();
            } catch (Exception e) {
               System.out.println("...... h.entrySet()");
               e.printStackTrace();
            }
         }

      }

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                martin Martin Buchholz
                Reporter:
                ndcosta Nelson Dcosta (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: