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

BeanComparator should handle null property values (?)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • Nightly Builds
    • None
    • None
    • None
    • Operating System: other
      Platform: Other

    • 18791

    Description

      Assume a "Person" with 3 string properties age, name, hairColor. We've got
      three people, Bob, Jane, and John - John happens to be bald, and his hairColor
      property is "null". Trying to sort a collection of Person beans by hairColor
      with a null entry throws a ClassCastException from ComparableComparator.

      " java.lang.ClassCastException: There were nulls in the arguments for this
      method: compare(hawkeye, null)' "

      One should be able to sort a collection of beans on a property which contains
      null values. The question that remains is whether the comparing with a null
      should return a 1 or a -1 (do you want your nulls in the beginning or at the
      end?). I'd assume at the end as the default behaviour - maybe add a property
      to allow people to customize this.

      Attachments

        Activity

          People

            Unassigned Unassigned
            tobrien@discursive.com Tim O'Brien
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: