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

RFE: Inner classes of java.util collections should be serializable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.3.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: rmT116609 Date: 10/24/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-beta_refresh)
      Java HotSpot(TM) Client VM (build 1.3.0-beta_refresh, mixed mode)


      I need in some cases the view of a HashMap's keys as a set (or even worse
      an Iterator over this set) explicitly stored in an Object which has to be
      serializable.
      Since the Iterator given by the map is not serializable this does not work.


      import java.util.*;
      import java.io.*;

      public class SerBug implements Serializable {
          
          Map m = new HashMap();
          Iterator it = m.keySet().iterator();

          public static void main (String args[]) throws Exception {
      ObjectOutputStream out = new ObjectOutputStream(new
      FileOutputStream("bug.out"));
      out.writeObject(new SerBug());
          }
      }


      > - The exact text of any error message(s) that appeared.

      java SerBug

      Exception in thread "main" java.io.NotSerializableException:
      java.util.HashMap$EmptyHashIterator
              at
      java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)
              at
      java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
              at
      java.io.ObjectOutputStream.outputClassFields(ObjectOutputStream.java:1841)
              at
      java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:480)
              at
      java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1214)
              at
      java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
              at SerBug.main(SerBug.java:11)

      > - Any trace information.

      It is obviously that the inner class does not implement the Serializable
      interface (which will change soon, I hope).

      The problem is not alone with the iterator in a HashMap. It is common to
      a
      lot of inner classes in the java.util package (for instance the sublist)
      and is IMHO simply unnecessary.
      (Review ID: 109057)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jjb Josh Bloch
                Reporter:
                rmandalasunw Ranjith Mandala (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: