Commons BeanUtils
  1. Commons BeanUtils
  2. BEANUTILS-61

PropertyUtilsBean isReadable() and isWriteable() methods do not work correctly for WrapDynaBean

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: Nightly Builds
    • Fix Version/s: 1.8.0
    • Component/s: DynaBean
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: All

      Description

      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.

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        758d 1h 18m 1 Niall Pemberton 05/Jul/07 02:16
        Resolved Resolved Closed Closed
        264d 6h 51m 1 Henri Yandell 25/Mar/08 08:07
        Henri Yandell made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Niall Pemberton made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Hide
        Niall Pemberton added a comment -

        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

        Show
        Niall Pemberton added a comment - 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
        Niall Pemberton made changes -
        Summary [beanutils] PropertyUtilsBean does not work correctly for WrapDynaBean PropertyUtilsBean isReadable() and isWriteable() methods do not work correctly for WrapDynaBean
        Assignee Niall Pemberton [ niallp ]
        Henri Yandell made changes -
        Bugzilla Id 35240
        Fix Version/s 1.8.0 [ 12311949 ]
        Niall Pemberton made changes -
        Component/s DynaBean [ 12311457 ]
        Bugzilla Id 35240
        Henri Yandell made changes -
        Affects Version/s Nightly Builds [ 12311692 ]
        Henri Yandell made changes -
        Component/s BeanUtils [ 12311101 ]
        Affects Version/s Nightly Builds [ 12311648 ]
        Project Commons [ 12310458 ] Commons BeanUtils [ 12310460 ]
        Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
        Key COM-2136 BEANUTILS-61
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 35240 12342288
        Brian Ewins created issue -

          People

          • Assignee:
            Niall Pemberton
            Reporter:
            Brian Ewins
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development