|
Description
|
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
customer Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When using new PropertyDescriptor(), the resultant property descriptor differs to that returned from BeanInfo.getPropertyDescriptors() for bound properties.
This is because BeanInfo takes into account the design pattern for bound properties (the existance of add/removePropertyChangeListener methods) and sets the bound field accordingly, whereas the PropertyDescriptor constructor makes no such check and always defaults to bound being false.
This proves to be a problem when testing for equality between PropertyDescriptors since the bound field comprises part of the equality test.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test source.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Property index = 1
ACTUAL -
Property index = -1
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyChangeListener;
import java.beans.PropertyDescriptor;
public class BeanBugTest
{
public void addPropertyChangeListener(PropertyChangeListener listener)
{
}
public void removePropertyChangeListener(PropertyChangeListener listener)
{
}
public int getFoo()
{
return 0;
}
public void setFoo(int foo)
{
}
public static void main(String[] args) throws Exception
{
BeanInfo info = Introspector.getBeanInfo(BeanBugTest.class);
PropertyDescriptor[] properties = info.getPropertyDescriptors();
PropertyDescriptor fooProperty = new PropertyDescriptor("foo", BeanBugTest.class);
int index = -1;
for (int i = 0; i < properties.length; i++)
if (properties[i].equals(fooProperty))
index = i;
System.out.println("Property index = " + index);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
When instantiating a PropertyDescriptor using the constructor, e.g.:
PropertyDescriptor fooProperty = new PropertyDescriptor("foo", BeanBugTest.class);
Add the following to correctly set the bound field:
try
{
EventSetDescriptor eventSet = new EventSetDescriptor(BeanBugTest.class, "propertyChange", PropertyChangeListener.class, "propertyChange");
fooProperty.setBound(true);
}
catch (IntrospectionException exception)
{
}
xxxxx@xxxxx 2004-11-12 19:13:24 GMT
|