United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-8013557 XMLEncoder in 1.7 can't encode objects initialized in no argument constructor
JDK-8013557 : XMLEncoder in 1.7 can't encode objects initialized in no argument constructor

Details
Type:
Bug
Submit Date:
2013-04-04
Status:
Resolved
Updated Date:
2013-12-17
Project Name:
JDK
Resolved Date:
2013-05-31
Component:
client-libs
OS:
Sub-Component:
java.beans
CPU:
Priority:
P3
Resolution:
Fixed
Affected Versions:
7u13,8
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:
Duplicate:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version  " 1.7.0_13 " 
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux silent 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:31:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
The behavior of XMLEncoder changed in Java 1.7 such that it is no longer compatible with any class that initializes the values of objects inside its no argument constructor.  Objects of primitive types (e.g. Integer) seem to work OK, but more complex objects it doesn't work.  Note that all the code works just fine in Java 1.6.  This bug is bad enough that XMLEncoder is no longer usable in 1.7 and I'm not aware of any work around.

-------- Serialization Code -------------

Hack o = new Hack(new Vector3D_F64(1,2,3));
XMLEncoder encoder = null;
try {
encoder = new XMLEncoder(
new FileOutputStream(fileName)
);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}

encoder.writeObject(o);
encoder.close();

-------- Class To Be Serialized --------------

public class Hack implements Serializable {
public Vector3D_F64 value;

public Hack() {
// Serialization works when the line below is commented out
value = new Vector3D_F64();
}

public Hack(Vector3D_F64 value) {
this.value = value;
}

public Vector3D_F64 getValue() {
return value;
}

public void setValue(Vector3D_F64 value) {
this.value = value;
}
} 

-------------- Broken 1.7 Output ---------------
<?xml version= " 1.0 "  encoding= " UTF-8 " ?>
<java version= " 1.7.0_13 "  class= " java.beans.XMLDecoder " >
 <object class= " boofcv.examples.Hack "  id= " Hack0 " />
</java>

------------- Output when the line above is commented out ---------------------------

<?xml version= " 1.0 "  encoding= " UTF-8 " ?>
<java version= " 1.7.0_13 "  class= " java.beans.XMLDecoder " >
 <object class= " boofcv.examples.Hack "  id= " Hack0 " >
  <void class= " boofcv.examples.Hack "  method= " getField " >
   <string>value</string>
   <void method= " set " >
    <object idref= " Hack0 " />
    <object class= " georegression.struct.point.Vector3D_F64 "  id= " Vector3D_F640 " >
     <void class= " georegression.struct.GeoTuple3D_F64 "  method= " getField " >
      <string>x</string>
      <void method= " set " >
       <object idref= " Vector3D_F640 " />
       <double>1.0</double>
      </void>
     </void>
     <void class= " georegression.struct.GeoTuple3D_F64 "  method= " getField " >
      <string>y</string>
      <void method= " set " >
       <object idref= " Vector3D_F640 " />
       <double>2.0</double>
      </void>
     </void>
     <void class= " georegression.struct.GeoTuple3D_F64 "  method= " getField " >
      <string>z</string>
      <void method= " set " >
       <object idref= " Vector3D_F640 " />
       <double>3.0</double>
      </void>
     </void>
    </object>
   </void>
  </void>
 </object>
</java>

REGRESSION.  Last worked in version 6u31


REPRODUCIBILITY :
This bug can be reproduced always.
                                    

Comments
URL:   http://hg.openjdk.java.net/jdk8/awt/jdk/rev/611f8664c96c
User:  malenkov
Date:  2013-05-31 14:26:35 +0000

                                     
2013-05-31
URL:   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/611f8664c96c
User:  lana
Date:  2013-06-11 18:41:37 +0000

                                     
2013-06-11



Hardware and Software, Engineered to Work Together