-
Bug
-
Resolution: Fixed
-
P3
-
1.1.3
-
None
-
1.1.5
-
sparc
-
solaris_2.5.1
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2016107 | 1.2.0 | Joe Fialli | P3 | Resolved | Fixed | 1.2beta |
Name: rlT66838 Date: 07/17/97
Altough the documentation mentions that one can replace
an object with the null value in the replaceObject method
of ObjectOutputStream, doing this always results in a
NullPointerException at ObjectOutputStream.writeObject(Object)
Here is some sample code :
_______________________________________________________
import java.io.*;
class A { }
class MyObjectOutputStream extends ObjectOutputStream {
public MyObjectOutputStream(OutputStream out) throws IOException {
super(out);
enableReplaceObject(true);
}
protected Object replaceObject(Object obj) throws IOException {
if(obj instanceof A) return null;
else return obj;
}
}
class Main {
public static void main(String argv[]) {
try {
A a = new A();
MyObjectOutputStream out = new MyObjectOutputStream(new FileOutputStream("test"));
out.writeObject(a);
out.flush();
out.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
======================================================================
- backported by
-
JDK-2016107 One cannot replace an object with a null value
-
- Resolved
-