harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Ellison <t.p.elli...@gmail.com>
Subject Re: [classlib][beans] analyzing indexed properties
Date Thu, 16 Nov 2006 22:11:10 GMT
Looks like an RI bug to me.  I'd expect it to return the property:
       public String[] getProp1()
       public void setProp1(String[] val)

Regards,
Tim

Alexei Zakharov wrote:
> Hi all,
> 
> I'd like to propose another [beans] topic for discussion. IMHO RI's
> Introspector behaves oddly during analyzing some exotic beans. Let's
> look at the following piece of code for example:
> 
> ---
> import java.beans.*;
> 
> public class TestIntrospector2 {
> 
>    public static class MyParent {
>        public Integer getProp1(int i) {
>            return new Integer(1);
>        }
> 
>        public void setProp1(int i, Integer val) {}
>    }
> 
>    public static class MyClass extends MyParent {
>        public String[] getProp1() {
>            return new String[2];
>        }
> 
>        public void setProp1(String[] val) {}
>    }
> 
>    public static void main(String[] argv)  throws Exception {
>        BeanInfo binfo = Introspector.getBeanInfo(MyClass.class,
> Object.class);
>        PropertyDescriptor[] pds = binfo.getPropertyDescriptors();
> 
>        for (PropertyDescriptor pd : pds) {
>            System.out.println("Name: " + pd.getName());
>            System.out.println("Descriptor type: " +
> pd.getClass().getName());
>            System.out.println("Property type: " + pd.getPropertyType());
>            if (pd instanceof IndexedPropertyDescriptor) {
>                System.out.println("Property indexed type: " +
>                        ((IndexedPropertyDescriptor)
> pd).getIndexedPropertyType());
>            }
>        }
>    }
> }
> ---
> 
> The output on RI is the following:
> 
> Name: prop1
> Descriptor type: java.beans.IndexedPropertyDescriptor
> Property type: null
> Property indexed type: class java.lang.Integer
> 
> So it identifies an indexed property here. But it is nonsense since
> array accessor methods have the type that differs from the one of
> regular accessor methods. More formal: this is against the design
> patterns for indexed properties described in JavaBeans spec (ยง 8.3.3,
> pages 55-56). So my assumption is we should report the regular
> property that has String[] type here. Any thoughts, objections?
> 
> Thanks.
> 

-- 

Tim Ellison (t.p.ellison@gmail.com)
IBM Java technology centre, UK.

Mime
View raw message