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

XMLEncoder.writeObject is ignore the selection state of java.awt.Choice

XMLWordPrintable

    • sparc
    • solaris_2.6



      Name: dsR10051 Date: 09/18/2001


      Method of class java.beans.XMLEncoder
      protected void writeObject(Object o)
      is ignore the selection state of the java.awt.Choice object.
      If the selected index is differ from default, the selected index
      of the object being read is not the same as the selected index
      of the object being writen that is always set to default.

      Here is minimized test:
      import java.io.*;
      import java.beans.*;
      import java.awt.*;

      public class Test0009_01 {

          public static void main(String[] args) {

              Choice choice = new Choice();
              choice.addItem("Item 1");
              choice.addItem("Item 2");

              choice.select(1);

              ByteArrayOutputStream os = new ByteArrayOutputStream();
              XMLEncoder xmlEnc = new XMLEncoder(os);
              xmlEnc.writeObject(choice);
              xmlEnc.flush();
              xmlEnc.close();

              ByteArrayInputStream in = new ByteArrayInputStream(os.toByteArray());
              XMLDecoder xmlDec = new XMLDecoder(in);
              System.out.println("OutputStream");
              System.out.println(os.toString());

              Choice res = (Choice) xmlDec.readObject();
              if(res.getSelectedIndex() == choice.getSelectedIndex()) {
                  System.out.println("OKAY");
              } else {
                  System.out.println("Failed");
                  System.out.println("Selected index is: " + res.getSelectedIndex());
                  System.out.println("Should be : " + choice.getSelectedIndex());
              }
          }
      }

      --- Output ---
      $ /set/jdk-builds/JDK1.4.0beta2-b78/solaris/bin/java Test0009_01
      OutputStream
      <?xml version="1.0" encoding="UTF-8"?>
      <java version="1.4.0-beta3" class="java.beans.XMLDecoder">
       <object class="java.awt.Choice">
        <void property="name">
         <string>choice0</string>
        </void>
        <void method="add">
         <string>Item 1</string>
        </void>
        <void method="add">
         <string>Item 2</string>
        </void>
       </object>
      </java>

      Failed
      Selected index is: 0
      Should be : 1
      $

      ======================================================================

            mdavidsosunw Mark Davidson (Inactive)
            sdasunw Sda Sda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: