Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-5975

[classlib] [beans] XMLEncoder encodes the static field with customized persistence delegate

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.0M7
    • 5.0M8
    • Classlib
    • None
    • Moderate

    Description

      Consider test case [1], RI and Harmony's beans will generate different results [2] [3].
      Using the given MockObjectPersistenceDelegate, RI will write the "inst" instance of MockObject as a field,
      while current Harmony's beans will write this instance by using reflection method Class.getField(...).
      This is due to the missing condition in the XMLEncoder.flushStatField(...) method.

      [1]
      public class XMLEncoderTest extends TestCase {
      public void test_WriteObject_StaticField()

      { ByteArrayOutputStream bos = new ByteArrayOutputStream(); XMLEncoder xmlEncoder = new XMLEncoder(bos); xmlEncoder.setPersistenceDelegate(MockObject.class, new MockObjectPersistenceDelegate()); xmlEncoder.writeObject(MockObject.inst); xmlEncoder.close(); System.out.println(bos.toString()); }

      public static class MockObject

      { public static MockObject inst = new MockObject(); }

      public static class MockObjectPersistenceDelegate extends
      PersistenceDelegate {
      protected Expression instantiate(Object oldInstance, Encoder enc) {
      Expression exp = null;
      try {
      exp = new Expression(MockObject.class.getField("inst"), "get",
      new Object[]

      { null }

      );
      } catch (Exception e)

      { e.printStackTrace(); }

      return exp;
      }
      }
      }

      [2] RI's XML:
      <?xml version="1.0" encoding="UTF-8"?>
      <java version="1.6.0_05" class="java.beans.XMLDecoder">
      <object class="tests.java.beans.XMLEncoderTest$MockObject" field="inst"/>
      </java>

      [3] Harmony's XML
      <?xml version="1.0" encoding="UTF-8"?>
      <java version="1.5.0" class="java.beans.XMLDecoder">
      <object class="tests.java.beans.XMLEncoderTest$MockObject" method="getField">
      <string>inst</string>
      </object>
      </java>

      Attachments

        1. HARMONY-5975.diff
          13 kB
          Kevin Zhou

        Activity

          People

            zhoukevin Kevin Zhou
            zhoukevin Kevin Zhou
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 24h
                24h
                Remaining:
                Remaining Estimate - 24h
                24h
                Logged:
                Time Spent - Not Specified
                Not Specified