-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.4.1
-
x86
-
windows_2000
Name: gm110360 Date: 03/21/2003
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
Serialized form of the bean is corrupt and does not
correspond to the actual bean state. It cannot be deserialized
back.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Compile&Run attached class
2.
3.
EXPECTED VERSUS ACTUAL BEHAVIOR :
The serialized form of the bean contains broken object
references. Serialized object is below:
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.0" class="java.beans.XMLDecoder">
<object class="Test">
<void property="table">
<void method="put">
<void class="Test">
<void property="table">
<void method="put">
<object idref="Font0"/>
<string>qqqqqqqqqqqq</string>
</void>
</void>
<void id="Font0" property="key"/>
</void>
<object idref="Font0"/>
<string>qqqqqqqqqqqq</string>
</void>
</void>
<void id="Font0" property="key"/>
</object>
</java>
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.Exception: Unbound variable: Font0
Continuing ...
java.lang.NullPointerException
Continuing ...
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.HashMap;
import java.util.Arrays;
import java.beans.XMLEncoder;
import java.beans.XMLDecoder;
import java.io.*;
import java.awt.Font;
public class Test {
private Font key = new Font("Arial", Font.BOLD, 12); // !!!
private HashMap table = new HashMap();
public Test() {
}
public Font getKey() {
return key;
}
public void setKey(Font key) {
this.key = key;
}
public HashMap getTable() {
return table;
}
public void setTable(HashMap table) {
this.table = table;
}
public void setString(String value) {
table.put(getKey(), value);
}
public static void main(String[] args) {
try {
Test lr = new Test();
lr.setString("qqqqqqqqqqqq");
write(lr, new FileOutputStream("test.xml"));
read(new FileInputStream("test.xml"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void write(Object obj, OutputStream out) throws
IOException {
BufferedOutputStream bout = new BufferedOutputStream
(out);
XMLEncoder encoder = new XMLEncoder(out);
encoder.writeObject(obj);
encoder.close();
bout.close();
}
public static Object read(InputStream in) throws IOException {
XMLDecoder decoder = new XMLDecoder(in);
Object result = decoder.readObject();
decoder.close();
return result;
}
}
---------- END SOURCE ----------
(Review ID: 146830)
======================================================================
- duplicates
-
JDK-4679556 XMLEncoder can be configured to produce invalid archives
- Resolved