JDK-4206915 : Introspector doesn't report a r/w property if setProperty is overloaded
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.2.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5
  • CPU: unknown
  • Submitted: 1999-01-28
  • Updated: 1999-04-27
  • Resolved: 1999-04-27
Related Reports
Duplicate :  
Description
/*

In the example below we expect the java beans Introspector to find a single
read/write property called "foo".  Currently it produces a read-only
PropertyDescriptor instead, because setFoo() is overloaded.  This scenario
comes up in both the AWT classes, e.g. the Scrollbar.visible property, 
and in Swing, e.g. the AbstractButton.mnemonic property.  

*/

import java.beans.*;
import java.lang.reflect.*;


class FooProperty1 {
    public String getFoo() {
	return "";
    }

    public void setFoo(String x) {
    }

    public void setFoo(Object x) {
	setFoo(x.toString());
    }
}


public class IntrospectorBug
{
    /** 
     * Print the PropertyDescriptors computed by the java beans Introspector
     * for the FooProperty class.  We expect one read/write "foo" property.
     */
    public static void main(String[] args) throws Exception {
	BeanInfo info = java.beans.Introspector.getBeanInfo(FooProperty.class, Object.class);
	PropertyDescriptor[] pds = info.getPropertyDescriptors();
	for(int i = 0; i < pds.length; i++) {
	    System.out.println(propertyDescriptorString(pds[i]));
	}
    }

    /**
     * PropertyDescriptor.toString() doesn't do anything useful.  So we build
     * a nice string here.
     */
    static String propertyDescriptorString(PropertyDescriptor pd) {
	String classString = pd.getClass().getName();
	String nameString = " \"" + pd.getName() + "\"";

	Class type = pd.getPropertyType();
	String typeString = (type != null) ? " type " + type.getName() : " <null type>";

	Method reader = pd.getReadMethod();
	Method writer = pd.getWriteMethod();
	String accessString = "";
	if ((reader == null) && (writer == null)) {
	    accessString = " <no access>";
	}
	else if (reader == null) {
	    accessString = " write-only";
	}
	else if (writer == null) {
	    accessString = " read-only";
	}

	return  "#<" + classString + nameString + typeString + accessString + ">";
    }
}