You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Alexei Zakharov <al...@gmail.com> on 2006/11/16 15:20:46 UTC

[classlib][beans] analyzing indexed properties

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.

-- 
Alexei Zakharov,
Intel Enterprise Solutions Software Division

Re: [classlib][beans] analyzing indexed properties

Posted by Alexei Zakharov <al...@gmail.com>.
Thanks for the review Tim. I'm going to file "non-bug" JIRA if no one objects.

Regards,

2006/11/17, Tim Ellison <t....@gmail.com>:
> 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.


-- 
Alexei Zakharov,
Intel Enterprise Solutions Software Division

Re: [classlib][beans] analyzing indexed properties

Posted by Tim Ellison <t....@gmail.com>.
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.