[ 
https://issues.apache.org/jira/browse/BEANUTILS-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12746891#action_12746891
 ] 

Richard O'Sullivan commented on BEANUTILS-357:
----------------------------------------------

Niall, I found the issue while using BeanUtils 1.8.0 but ran the unit tests 
using truck (1.9-SNAPSHOT).
Since my initial posting, I narrowed the issue down to the following test case. 

The test below fails due to 'expected:<class 
org.apache.commons.beanutils.TestBean$InnerClass> but was:<class 
org.apache.commons.beanutils.AbstractTestBean$InnerClass>'. My expectation is 
that the PropertyDescriptor for the "innerClassProperty" should be the 
subclass's type instead of the super's type; but, the test indicates the 
opposite is occurring.

Background: I encountered this issue while using Wicket Web Beans (WWB) to 
auto-generate forms. WWB calls PropertyUtils.getPropertyDescriptors() on a bean 
to reflectively generate a web form. In my case, the resulting form did not 
include my equivalent of 'TestBean.InnerClass' because, I believe, 
PropertyUtils returned AbstractTestBean$InnerClass instead of 
TestBean$InnerClass.

1) Add this to AbstractTestBean:

        public abstract static class InnerClass
        {
                // Subclass implements properties here.
                private String firstName;
                public String getInnerName() { return firstName; }
                public void setInnerName(String firstName) { this.firstName = 
firstName; };
        }
        public abstract AbstractTestBean.InnerClass getInnerClassProperty();

2) Add implementation to TestBean:

        public static class InnerClass extends AbstractTestBean.InnerClass
        {
                private String lastName;
                public String getLastName() { return lastName;  }
                public void setLastName(String lastName) { this.lastName = 
lastName; }
        }
        private TestBean.InnerClass innerClassProperty;
        public TestBean.InnerClass getInnerClassProperty()
        {
                return innerClassProperty;
        }
        public void setInnerClassProperty(TestBean.InnerClass 
innerClassProperty)
        {
                this.innerClassProperty = innerClassProperty;
        }

3) Add test case to PropertyUtilsTestCase:

    /**
     * Positive getPropertyDescriptor on property 
<code>innerClassProperty</code>.
     */
    public void testGetDescriptorInnerClass() {
        String propName = "innerClassProperty";
        try {
            PropertyDescriptor pd =
                    PropertyUtils.getPropertyDescriptor(bean, propName);
            assertEquals(TestBean.InnerClass.class, pd.getPropertyType());
        } catch (IllegalAccessException e) {
                fail("IllegalAccessException");
                } catch (InvocationTargetException e) {
                fail("InvocationTargetException");
                } catch (NoSuchMethodException e) {
                fail("NoSuchMethodException");
                }
        testGetDescriptorBase(propName, "getInnerClassProperty",
                "setInnerClassProperty");
    }


> PropertyUtilsTestCase.testGetReadMethod* fail for abstract properties.
> ----------------------------------------------------------------------
>
>                 Key: BEANUTILS-357
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-357
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: Bean / Property Utils
>         Environment: Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
> Linux 2.6.24-22-generic #1 SMP Mon Nov 24 18:32:42 UTC 2008 i686 GNU/Linux
>            Reporter: Richard O'Sullivan
>         Attachments: AbstractTestBean.java, 
> BEANUTILS-357-AbstractTestBean.patch
>
>
> Create org.apache.commons.beanutils.AbstractTestBean with abstract methods 
> for properties in TestBean and change TestBean to extend AbstractTestBean. 
> Run PropertyUtilsTestCase, the testGetReadMethod* methods fail because 
> "Correct declaring class for X expected:<...Abstract...> but was:<......>".

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to