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

XMLEncoder fails to encode and breaks backward compatibility

XMLWordPrintable

    • b17
    • x86
    • windows_xp, windows_vista

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

        ADDITIONAL OS VERSION INFORMATION :
        Confirmed under Windows Vista and 7 32bit, XP and 64bit untested

        A DESCRIPTION OF THE PROBLEM :
        XMLEncoder fails to encode a bean when it extends an interface with getters that have generic type.


        REGRESSION. Last worked in version 7

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        run the test case under java 7

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        output from java 6:

        <?xml version="1.0" encoding="UTF-8"?>
        <java version="1.6.0_22" class="java.beans.XMLDecoder">
         <object class="test.Test$WorkingBean">
          <void property="cod_id">
           <int>99</int>
          </void>
         </object>
         <object class="test.Test$BrokenBean">
          <void property="cod_id">
           <int>99</int>
          </void>
         </object>
        </java>
        ACTUAL -
        cod_id doesn't get serialised
        output from java 7:

        java.lang.NoSuchMethodException: <unbound>=Test$BrokenBean.getCod_id();
        Continuing ...
        <?xml version="1.0" encoding="UTF-8"?>
        <java version="1.7.0" class="java.beans.XMLDecoder">
         <object class="test.Test$WorkingBean">
          <void property="cod_id">
           <int>99</int>
          </void>
         </object>
         <object class="test.Test$BrokenBean"/>
        </java>


        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        java.lang.NoSuchMethodException: <unbound>=Test$BrokenBean.getCod_id();
        Continuing ...

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        package test;

        import java.beans.XMLEncoder;

        public class Test {
        public static class WorkingBean {
        private Integer cod_id;

        public WorkingBean() {

        }

        public Integer getCod_id() {
        return cod_id;
        }

        public void setCod_id(Integer cod_id) {
        this.cod_id = cod_id;
        }
        }


        public static class BrokenBean implements WithCodId<Integer> {
        protected Integer cod_id;

        public BrokenBean() {

        }

        public Integer getCod_id() {
        return cod_id;
        }

        public void setCod_id(Integer cod_id) {
        this.cod_id = cod_id;
        }
        }

        public static interface WithCodId<T extends Number> {
        T getCod_id();
        void setCod_id(T value);
        }

        public static void main(String[] args) {
        WorkingBean b1 = new WorkingBean();
        b1.setCod_id(99);

        BrokenBean b2 = new BrokenBean();
        b2.setCod_id(99);

        XMLEncoder enc = new XMLEncoder(System.out);
        enc.writeObject(b1);
        enc.writeObject(b2);
        enc.close();
        }
        }


        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Hardcode type in the WithCodId interface.

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

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: