harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexei Zakharov" <alexei.zakha...@gmail.com>
Subject [classlib][beans] analyzing indexed properties
Date Thu, 16 Nov 2006 14:20:46 GMT
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: " +

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?


Alexei Zakharov,
Intel Enterprise Solutions Software Division

View raw message