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

        No work has yet been logged on this 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