Name: gm110360 Date: 09/11/2003
FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195] SP 3
A DESCRIPTION OF THE PROBLEM :
If you Encode a java.util.HashMap containing en entry with
a "Key" and "null" for the value, then this entry will not
be included in the XML output.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a new java.util.HashMap
2. Add some entries using the "put" method
3. Add one entry like the following put("Key1", null);
4. decode the map using the java.beans.XMLEncoder
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected result:
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.1_01" class="java.beans.XMLDecoder">
<object class="java.util.HashMap">
<void method="put">
<string>Key4</string>
<string>4</string>
</void>
<void method="put">
<string>Key3</string>
<null/>
</void>
<void method="put">
<string>Key1</string>
<string>1</string>
</void>
<void method="put">
<string>Key5</string>
<string>5</string>
</void>
<void method="put">
<string>Key2</string>
<string>2</string>
</void>
<void method="put">
<null/>
<string>6</string>
</void>
<void method="put">
<string>Key7</string>
<string>7</string>
</void>
</object>
</java>
Actual Result:
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.1_01" class="java.beans.XMLDecoder">
<object class="java.util.HashMap">
<void method="put">
<string>Key4</string>
<string>4</string>
</void>
<void method="put">
<string>Key1</string>
<string>1</string>
</void>
<void method="put">
<string>Key5</string>
<string>5</string>
</void>
<void method="put">
<string>Key2</string>
<string>2</string>
</void>
<void method="put">
<null/>
<string>6</string>
</void>
<void method="put">
<string>Key7</string>
<string>7</string>
</void>
</object>
</java>
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Map myMap;
myMap = new HashMap();
myMap.put("Key1", "1");
myMap.put("Key2", "2");
myMap.put("Key3", null);
myMap.put("Key4", "4");
myMap.put("Key5", "5");
myMap.put(null, "6");
myMap.put("Key7", "7");
try {
XMLEncoder encoder = new XMLEncoder(new
BufferedOutputStream(new FileOutputStream("c:\\Test.xml")));
encoder.writeObject(myMap);
encoder.close();
} catch (Exception e) {
e.printStackTrace();
}
---------- END SOURCE ----------
(Incident Review ID: 181400)
======================================================================