-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.3.1
-
generic
-
generic
Name: ddT132432 Date: 09/11/2001
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
The methods keySet(), entrySet() and values() return objects that are instances
of anonymous inner classes. These anonymous inner classes do not implement
Serializable, so that the Set objects returned by these methods are not
Serializable. This is inconsistent with the standard JDK collections
implementation classes, which all implement Serializable.
This bug leads to unexpected results, see the example program below.
import java.io.*;
import java.util.*;
public class MyTest {
public static void main(String[] args) throws Exception {
Map myMap = new HashMap();
myMap.put(new Integer(1), "one");
myMap.put(new Integer(2), "two");
FileOutputStream fos = new FileOutputStream("test.dat");
ObjectOutputStream oos = new ObjectOutputStream(fos);
Set obj = myMap.keySet(); // NOTE: This set is NOT Serializable!
oos.writeObject(obj); // Throws an NotSerializableException
oos.flush();
oos.close();
System.out.println("Success!");
}
}
(Review ID: 131494)
======================================================================
- relates to
-
JDK-6750650 java.util.HashMap.keySet() returns a non-serializable (Abstract) Set
-
- Closed
-