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

Harald Brabenetz commented on BEANUTILS-443:
--------------------------------------------

The Beans are correct. I only added some interfaces for a ReadOnly 
representation of my Beans. And all getter should return the readonly 
representation of the return type.
After adding the interfaces the application falling apart.
It is fixed in JDK 7.
I don't know exactly how, but org.springframework.beans.BeanUtils has solved 
this problem (it also solved some problems with generics)

{code:title=PropertyUtilsSetValueUTest.java|borderStyle=solid}
    @Test
    public void testPropertyDescriptorJdk() throws Exception {

        final PropertyDescriptor[] propDescrs = 
Introspector.getBeanInfo(MyEntity.class).getPropertyDescriptors();
        final PropertyDescriptor propDescr = getPropertyDescriptor(propDescrs, 
"otherEntity");
        LOG.info("JDK Prop '{}' has the Type: {}", propDescr.getName(), 
propDescr.getPropertyType().getSimpleName());
        // this will print in JDK 6: JDK Property 'otherEntity' has the Type: 
OtherEntityInterface
        // this will print in JDK 7: JDK Property 'otherEntity' has the Type: 
OtherEntity
    }

    @Test
    public void testPropertyDescriptorSpringBeans() throws Exception {
        final PropertyDescriptor[] propDescrs = 
org.springframework.beans.BeanUtils.getPropertyDescriptors(MyEntity.class);
        final PropertyDescriptor propDescr = getPropertyDescriptor(propDescrs, 
"otherEntity");
        LOG.info("Spring Prop '{}' has the Type: {}", //
                propDescr.getName(), 
propDescr.getPropertyType().getSimpleName());
        // this will print in JDK 6 and 7: Spring Property 'otherEntity' has 
the Type: OtherEntity
    }

    private static PropertyDescriptor getPropertyDescriptor(final 
PropertyDescriptor[] propDescrs,
            final String property) {
        for (final PropertyDescriptor propDescr : propDescrs) {
            if (propDescr.getName().equals(property)) {
                return propDescr;
            }
        }
        return null;
    }
{code}

> PropertyUtils.setProperty(...) cannot find the Setter method if returnValue 
> doesn't exact match the interface return value.
> ---------------------------------------------------------------------------------------------------------------------------
>
>                 Key: BEANUTILS-443
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-443
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: Bean / Property Utils
>    Affects Versions: 1.8.3
>         Environment: at least Java 1.6.0_33 on ubuntu
>            Reporter: Harald Brabenetz
>            Priority: Critical
>
> Here is My testClass:
> {code:title=PropertyUtilsSetValueUTest.java|borderStyle=solid}
> import org.apache.commons.beanutils.PropertyUtils;
> import org.junit.Test;
> public class PropertyUtilsSetValueUTest {
>     @Test
>     public void testSetProperty() throws Exception {
>         final MyEntity entity = new MyEntity();
>         // fist set value manual
>         final OtherEntity otherEntity = new OtherEntity();
>         entity.setOtherEntity(otherEntity);
>         // second set value with PropertyUtils
>         PropertyUtils.setProperty(entity, "otherEntity", otherEntity);
>         // => java.lang.NoSuchMethodException: Property 'otherEntity' has no 
> setter method in class '... MyEntity'
>     }
>     public static class MyEntity implements MyEntityInterface {
>         private OtherEntity otherEntity;
>         @Override
>         public OtherEntity getOtherEntity() {
>             return this.otherEntity;
>         }
>         public void setOtherEntity(final OtherEntity otherEntity) {
>             this.otherEntity = otherEntity;
>         }
>     }
>     public static class OtherEntity implements OtherEntityInterface {
>     }
>     public static interface MyEntityInterface {
>         OtherEntityInterface getOtherEntity();
>     }
>     public static interface OtherEntityInterface {
>     }
> }
> {code} 



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to