JDK-4144543 : Introspection code may fail depending on method ordering.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.1.6,1.1.7,1.2.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,solaris_2.5,windows_95
  • CPU: generic,unknown,x86
  • Submitted: 1998-06-01
  • Updated: 1999-06-29
  • Resolved: 1999-06-29
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.
Other
1.3.0 betaFixed
Related Reports
Duplicate :  
Relates :  
Description

Name: tb29552			Date: 06/01/98


DESCRIPTION
=============

	java.beans has a bug in PropertyDescriptor when
it tries to check for read&write (setter&getter) methods for a property.
If the class provides 2 setters for the same property, for
convenience, the code in java.beans may fail depending
on which method is declared first in the class.

	This type of code is present even in SUN's BDK example.
For instance, BridgeTester has 2 methods "setByteValue" , one
where a byte is passed, and another one where an int is passed.
Because of the order in which these methods were defined the bug
does not appear.


STEPS TO RECREATE
====================

	Try to compile & run the 2 classes included below.
One will cause the exception, the other won't. The exception will be like this

C:\beans>java beans.SunsBug1
java.beans.IntrospectionException: type mismatch between read and write methods
        at java.beans.PropertyDescriptor.findPropertyType(PropertyDescriptor.java:252)
        at java.beans.PropertyDescriptor.<init>(PropertyDescriptor.java:63)
        at beans.SunsBug1.main(SunsBug1.java:25)


// -- = - =  - CLASS SunsBug1  - = - =  - = - =

package beans;

/**
 * This type was generated by a SmartGuide.
 */
public class SunsBug1 {
		private int foo = 0;

public SunsBug1 ( ) {
}
public int getFooValue () {
	return foo;
}
public static void main(java.lang.String[] args) {
	Object bean = null;
	try {
		bean = java.beans.Beans.instantiate (null, "beans.SunsBug1");
	
		java.beans.BeanInfo bi = java.beans.Introspector.getBeanInfo (bean.getClass());

		java.beans.PropertyDescriptor pd = new java.beans.PropertyDescriptor("fooValue", bean.getClass());
	} catch (Exception e) {e.printStackTrace();}	
	
}
public void setFooValue (byte newValue ) {
	foo = newValue;
}
public void setFooValue (int newValue ) {
	foo = newValue;
}
}

// - = - =  - = CLASS SunsBug2- =  - = - =  - = - =


package beans;

/**
 * This type was generated by a SmartGuide.
 */
public class SunsBug2 {
		private byte bar = 0;

public SunsBug2 ( ) {
}
public byte getBarValue () {
	return bar;
}
public static void main(java.lang.String[] args) {
	Object bean = null;
	try {
		bean = java.beans.Beans.instantiate (null, "beans.SunsBug2");
	
		java.beans.BeanInfo bi = java.beans.Introspector.getBeanInfo (bean.getClass());

		java.beans.PropertyDescriptor pd = new java.beans.PropertyDescriptor("barValue", bean.getClass());
	} catch (Exception e) {e.printStackTrace();}	
	
}
public void setBarValue (byte newValue ) {
	bar = newValue;
}
public void setBarValue (int newValue ) {
	bar = (byte) newValue;
}
}
(Review ID: 24072)
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: kestrel-beta FIXED IN: kestrel-beta INTEGRATED IN: kestrel-beta
14-06-2004

WORK AROUND Name: tb29552 Date: 06/01/98 POSSIBLE WORKAROUND ======================== With components you own, change the order in which you declare methods, but this may not work depending on the VM & native methods in Introspect. ======================================================================
11-06-2004

EVALUATION Hmm. The beans property designs patterns aren't really design to cope with cases where there are multiple setters for a given type. I guess there can only be one getter that matches the getXXX() pattern, so we should look for a matching setter and skip non-matching setters. This looks like something worth fixing, but at the P4 level. graham.hamilton@Eng 1998-07-20
20-07-1998