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

XMLEncoder.writeObject does not write limiting values of floats and doubles

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.0
    • client-libs
    • sparc
    • solaris_2.6



      Name: dsR10051 Date: 03/16/2001



      Method
      protected void writeObject(Object o) of class java.beans.XMLEncoder
      does not write next Float and Double objects to the output stream:
      Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY,
      Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NaN

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

      public class Test0007 {

          public static void main(String[] args) {
              ByteArrayOutputStream os = new ByteArrayOutputStream();
              Object[] objects = {new Float(Float.NaN), new Float(Float.NEGATIVE_INFINITY), new Float(Float.POSITIVE_INFINITY), new Double(Double.NEGATIVE_INFINITY), new Double(Double.POSITIVE_INFINITY)};
              XMLEncoder xmlEnc = new XMLEncoder(os);
              for (int i = 0; i < objects.length; i++) {
                  xmlEnc.writeObject(objects[i]);
              }
              xmlEnc.flush();
              xmlEnc.close();
              ByteArrayInputStream in = new ByteArrayInputStream(os.toByteArray());
              XMLDecoder xmlDec = new XMLDecoder(in);
                      System.out.println("OutputStream");
                      System.out.println(os.toString());
              for (int i = 0; i < objects.length; i++) {
                  Object res = xmlDec.readObject();
                  if (!objects[i].equals(res)) {
                      System.out.println("FAILED");
                      System.out.println("Object type: " + objects[i].getClass());
                      System.out.println("Result : " + res);
                      System.out.println("Expected: " + objects[i]);
                  }
              }
          }
      }
      --- Output ---
      %java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b55)
      Java HotSpot(TM) Client VM (build 1.4beta-B55, mixed mode)
      %java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b55)
      Java HotSpot(TM) Client VM (build 1.4beta-B55, mixed mode)
      %java Test0007
      java Test0007
      Warning:
          Cannot allocate colormap entry for default background

      java.lang.NumberFormatException: NaN
      Continuing ...
      java.lang.Exception: discarding statement XMLEncoder0.writeObject(Float0);
      Continuing ...
      java.lang.NumberFormatException: -Infinity
      Continuing ...
      java.lang.Exception: discarding statement XMLEncoder0.writeObject(Float1);
      Continuing ...
      java.lang.NumberFormatException: Infinity
      Continuing ...
      java.lang.Exception: discarding statement XMLEncoder0.writeObject(Float2);
      Continuing ...
      java.lang.NumberFormatException: -Infinity
      Continuing ...
      java.lang.Exception: discarding statement XMLEncoder0.writeObject(Double0);
      Continuing ...
      java.lang.NumberFormatException: Infinity
      Continuing ...
      java.lang.Exception: discarding statement XMLEncoder0.writeObject(Double1);
      Continuing ...
      java.lang.NumberFormatException: NaN
      Continuing ...
      java.lang.Exception: discarding statement XMLEncoder0.writeObject(Double2);
      Continuing ...
      OutputStream
      <?xml version="1.0" encoding="UTF-8"?>
      <java version="1.4.0-beta" class="java.beans.XMLDecoder">
      </java>

      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
              at java.beans.ObjectHandler.dequeueResult(XMLDecoder.java:270)
              at java.beans.XMLDecoder.readObject(XMLDecoder.java:148)
              at Test0007.main(Test0007.java:20)
      %

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

            pmilnesunw Philip Milne (Inactive)
            sdasunw Sda Sda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: