Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4921212

XMLEncoder does NOT encode NULL (value) entries in HashMap

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.4.0, 1.4.2, 1.4.2_01
    • Fix Version/s: 6
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b60
    • CPU:
      x86
    • OS:
      linux, windows_2000

      Description

      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)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              malenkov Sergey Malenkov (Inactive)
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: