United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7092744 XMLEncoder fails to encode and breaks backward compatibility
JDK-7092744 : XMLEncoder fails to encode and breaks backward compatibility

Details
Type:
Bug
Submit Date:
2011-09-20
Status:
Resolved
Updated Date:
2013-05-24
Project Name:
JDK
Resolved Date:
2011-12-14
Component:
client-libs
OS:
windows_vista,windows_xp
Sub-Component:
java.beans
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Duplicate:
Relates:
Relates:

Sub Tasks

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

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.
                                     
2011-10-17
EVALUATION

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



Hardware and Software, Engineered to Work Together