commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton (JIRA)" <j...@apache.org>
Subject [jira] Resolved: (BEANUTILS-61) PropertyUtilsBean isReadable() and isWriteable() methods do not work correctly for WrapDynaBean
Date Thu, 05 Jul 2007 01:17:04 GMT

     [ https://issues.apache.org/jira/browse/BEANUTILS-61?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Niall Pemberton resolved BEANUTILS-61.
--------------------------------------

    Resolution: Fixed

I have made the following changes:

PropertyUtilsBean:
   - isReadable() and isWriteable() methods now "unwrap"  any WrapDynaBean as you suggest.
   - copyProperties() now checks isReadable() when the source is a DynaBean
     (it already checked isWriteable() for target DynaBean)

BeanUtilsBean
   - copyProperties() now checks isReadable() when the source is a DynaBean
     (it already checked isWriteable() for target DynaBean)

http://svn.apache.org/viewvc?view=rev&revision=553357

> PropertyUtilsBean isReadable() and isWriteable() methods do not work correctly for WrapDynaBean
> -----------------------------------------------------------------------------------------------
>
>                 Key: BEANUTILS-61
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-61
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: DynaBean
>    Affects Versions: Nightly Builds
>         Environment: Operating System: other
> Platform: All
>            Reporter: Brian Ewins
>            Assignee: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.8.0
>
>
> Try this: given any pojo class MyBean.java,
> MyBean orig = new MyBean();
> MyBean dest = new MyBean();
> DynaBean db = new WrapDynaBean(dest);
> PropertyUtils.copyProperties(db, orig);
> You'll see an exception like:
> java.lang.IllegalArgumentException: Property 'class' has no write method
>         at org.apache.commons.beanutils.WrapDynaBean.set(WrapDynaBean.java:266)
> This surprised me because 'copyProperties()' does an 'isWritable()' check before
> it sets properties. However, what PropertyUtilsBean.isWritable actually does is
> this:
> if (bean instanceof DynaBean) {
>             // All DynaBean properties are writeable
>             return (((DynaBean) bean).getDynaClass().getDynaProperty(name) != null);
> } ...
> That's plainly wrong for a WrapDynaBean, since pretty much every wrapped object
> has a non-writable 'class' property. 
> A workaround for the immediate problem:
> if (db instanceof WrapDynaBean) {
>   PropertyUtils.copyProperties(((WrapDynaBean) db).getInstance(), src);
> } else {
>   PropertyUtils.copyProperties(dest, src);
> }
> ... the problem affects isReadable and isWritable, and hence copyProperties; to
> fix it for all cases would (I think) require unwrapping any WrapDynaBeans passed
> into those calls.
> I guess having a situation where you'd use PropertyUtils /and/ WrapDynaBeans is
> fairly unusual so this is just a minor bug.

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message