Commons BeanUtils
  1. Commons BeanUtils
  2. BEANUTILS-411

BeanUtilsBean.setProperty throws IllegalArgumentException if getter of nested property returns null

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.0, 1.8.1, 1.8.2, 1.8.3
    • Fix Version/s: 1.8.4
    • Component/s: Bean / Property Utils
    • Labels:
    • Environment:

      Apache Struts 1.3.10 (latest) uses commons-beanutils 1.8.0

      Description

      The issue is like #BEANUTILS-331, BEANUTILS-339 where BeanUtils.populate() -> BeanUtilsBean.setProperty throws an IllegalArgumentException when it should not.

      error situation (see attached JUnitTest):
      BeanUtilsBean.setProperty(bean,"foo.bar", value) with a nested property "foo.bar" where bean.getFoo() returns null.
      Line 903 (in 1.8.0 -1.8.3) getPropertyUtils().getProperty(target, resolver.next(name));
      returns null (because bean.getFoo() returns null) which is not handled correctly.
      The Exception is thrown in line 963 because target == null.

      expected:
      SetProperty should silently return like in the case the property does not exist.

      background:
      BeanUtils.populate(), BeanUtilsBean.setProperty are used by Struts to populate HTTP-Request-Parameters to form beans (form backing objects). The request sent by a browser when clicking a <input type="image" name="imgLink"...> contains parameters "imgLink.x" and "imgLink.y". These request parameters should not let to an error when populating to a bean which has the property "imgLink".
      The application should be able to process these parameters after bean populating, which is not possible now because populate fails.

      Test case to reproduce:
      public class BeanUtilsBeanTest extends TestCase
      {
      public void testSetProperty()
      throws Exception

      { DummyBean testBean = new DummyBean(); // nested==null BeanUtilsBean instance = new BeanUtilsBean(); /* fails with java.lang.IllegalArgumentException: No bean specified * Reason: getPropertyUtils().getProperty(target, resolver.next(name)); returnes null * because DummyBean.getImgLink() returns null */ instance.setProperty(testBean, "imgLink.x", "1"); }

      public class DummyBean
      {
      private String imgLink = null; // stays null

      public String getImgLink ()

      { return imgLink; }

      public void setImgLink(String imgLink)

      { this.imgLink = imgLink; }

      }
      }

      suggestion for a fix:
      Return after line 903 if getProperty returns null and therefor target becomes null.

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        347d 23h 45m 1 Benedikt Ritter 03/Mar/13 13:15
        Benedikt Ritter made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Benedikt Ritter added a comment -

        Fixed in r1452036. Thanks for the report!

        Show
        Benedikt Ritter added a comment - Fixed in r1452036. Thanks for the report!
        Benedikt Ritter made changes -
        Fix Version/s 1.8.4 [ 12314869 ]
        Benedikt Ritter made changes -
        Field Original Value New Value
        Assignee Benedikt Ritter [ britter ]
        Hide
        Benedikt Ritter added a comment -

        Hi Marucus,

        we can fix this in 1.8.4. Can you create a SVN patch file against trunk containing your test and the proposed fix?

        TIA!
        Benedikt

        Show
        Benedikt Ritter added a comment - Hi Marucus, we can fix this in 1.8.4. Can you create a SVN patch file against trunk containing your test and the proposed fix? TIA! Benedikt
        Marcus Zander created issue -

          People

          • Assignee:
            Benedikt Ritter
            Reporter:
            Marcus Zander
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development