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

LTP: Sometimes XMLEncoder does not encode public array fields

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.7.0"
      Java(TM) SE Runtime Environment (build 1.7.0-b147)
      Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
        Public array fields of a class are not encoded by XMLEncoder if the class' constructor assigns an array instance of same length to the filed.

      REGRESSION. Last worked in version 6u26

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See attached source code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The field y should be encoded in the resulting xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <java version="1.7.0" class="java.beans.XMLDecoder">
       <object class="com.vipersystems.input.X" id="X0">
        <void class="com.vipersystems.input.X" method="getField">
         <string>y</string>
         <void method="set">
          <object idref="X0"/>
          <array class="java.lang.String" length="1">
           <void index="0">
            <string>a</string>
           </void>
          </array>
         </void>
        </void>
       </object>
      </java>
      ACTUAL -
      The field is missing from output:
      <?xml version="1.0" encoding="UTF-8"?>
      <java version="1.7.0" class="java.beans.XMLDecoder">
       <object class="com.vipersystems.input.X" id="X0"/>
      </java>

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.beans.*;
      import java.io.*;
      import java.nio.file.*;

      public class X
      {
      public String[] y;

      public X()
      {
      y = new String[1];
      }

      public String[] getY()
      {
      return y;
      }

      public void setY(String[] y)
      {
      this.y = y;
      }

      public static void main(String[] args) throws IOException
      {
      X x = new X();
      x.setY(new String[]
      {
      "a"
      });

      Files.write(Paths.get("z.xml"), getXmlBytes(x));
      }

      private static byte[] getXmlBytes(Object o)
      {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      XMLEncoder xmle = new XMLEncoder(baos);
      xmle.writeObject(o);
      xmle.flush();
      xmle.close();
      return baos.toByteArray();
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      - don't use 'public' (in this case the gettets and setters are used)
      or
      - don't assign the field in constructor

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              malenkov Sergey Malenkov (Inactive)
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: