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

NullPointerException in BeanUtilsBean .setProperty(), line: 930

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.8.1
    • 1.8.2
    • Bean / Property Utils
    • None
    • JDK 1.6

    Description

      There is a NullPointerException in the method BeanUtilsBeans.setProperty(Object bean, String name, Object value) method:

      java.lang.NullPointerException
      at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:930)

      The problem is, that few rows earlear the target may be null:

      target = getPropertyUtils().getProperty(target, resolver.next(name)); // NOTE, the result may be NULL.

      In such case, the condition at line 930

      } else if (target.getClass().isArray() && index >= 0) {

      will race a NullPointerException. In the old 1.7.0 version there has been no such condition or has been executed later...

      Proposed FIX: Please add at new line, which checks the "target"

      target = getPropertyUtils().getProperty(target, resolver.next(name)); // NOTE, the result may be NULL.
      if (target == null)

      { return; }

      NOTE. Such check may be added also to the other similar methods, like BeanUtilsBean.copyProperty().

      Regards
      Peter

      Attachments

        Issue Links

        Activity

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

          People

            niallp Niall Pemberton
            fassev@gmx.de Peter Fassev
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment