Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6194788
Votes 0
Synopsis PropertyDescriptor constructor doesn't set bound field
Category java:classes_beans
Reported Against
Release Fixed 7(b20)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs
Submit Date 12-NOV-2004
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
Work Around
N/A
Evaluation
We should initialize property "bound" in constructor.
Posted Date : 2007-07-20 11:53:46.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang