Uploaded image for project: 'Commons BeanUtils'
  1. Commons BeanUtils
  2. BEANUTILS-14

BeanUtils.setProperty doesn't convert primitive wrappers

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5
    • None
    • None
    • None
    • Operating System: All
      Platform: All

    • 15170

    Description

      When using BeanUtils.setProperty to set a property of type String, sometimes
      it will be necessary to pass in an object of a primitive wrapper type (i.e.
      java.lang.Integer). The current implementation throws an
      IllegalArgumentException, ignoring the available toString() method on the
      primitive wrapper. The current conversion code also will not delegate the
      conversion to ConvertUtils.

      Here's an example that illustrates the error:

      BeanUtils.setProperty(new BeanComparator("foo"), "property", new Integer(1));

      (See the attached testcase for the entire testcase.)

      I have proposed a patch for this (see attached). However, I am not extremely
      familiar with the BeanUtils code. The patch will, however, enable primitive
      wrapper conversions to work correctly.

      Attachments

        1. ASF.LICENSE.NOT.GRANTED--BeanUtilsPatch.txt
          0.9 kB
          Runako Godfrey
        2. ASF.LICENSE.NOT.GRANTED--BeanUtilsPatch.txt
          1 kB
          Runako Godfrey
        3. ASF.LICENSE.NOT.GRANTED--BeanUtilsPatch2.txt
          2 kB
          Runako Godfrey
        4. ASF.LICENSE.NOT.GRANTED--BeanUtilsPatch2.txt
          0.9 kB
          Runako Godfrey
        5. ASF.LICENSE.NOT.GRANTED--BeanUtilsTest.java
          0.4 kB
          Runako Godfrey
        6. ASF.LICENSE.NOT.GRANTED--BeanUtilsTestCasePatch.txt
          1 kB
          Runako Godfrey

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            rg@onepercentsoftware.com Runako Godfrey
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment