JDK-7092744 : XMLEncoder fails to encode and breaks backward compatibility
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 7
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp,windows_vista
  • CPU: x86
  • Submitted: 2011-09-20
  • Updated: 2013-05-24
  • Resolved: 2011-12-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u4Fixed 8 b17Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
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.

Comments
EVALUATION We should skip all bridge methods.
25-10-2011

EVALUATION The problem is in the com.sun.beans.finder.AbstractFinder class. It does not handle the case when some class has two methods with different return types and with equal names and parameters.
17-10-2011