-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
1.3.0
-
generic
-
generic
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)
======================================================================
- relates to
-
JDK-5041584 (coll) TreeMap.SubMap should not be Serializable
-
- Closed
-