Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-331

CollatingIterator NPE when Comparator is null

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.2
    • Fix Version/s: 4.0-alpha1, 4.0
    • Component/s: Iterator
    • Labels:
      None

      Description

      Run the attached Test against commons-collections-3.2.1. While the JavaDoc for CollatingIterator claims

      @param comp the comparator to use to sort, or null to use natural sort order

      the test fails, because the comparator is null.

      Fixing this requires a change in org.apache.commons.collections.iterators.CollatingIterator.least():

      if (comparator.compare(curObject,leastObject) < 0) { ...
      

      could be replaced with

      int c = comparator==null?((Comparable)curObject).compareTo(leastObject):comparator.compare(curObject,leastObject);
      if (c < 0) { ...
      

      The workaround is to provide a comparator, of course.

        Attachments

        1. CollatingIteratorTest.java
          0.7 kB
          Michael Krkoska
        2. COLLECTIONS-331.patch
          3 kB
          Michael Krkoska

          Activity

            People

            • Assignee:
              jochen@apache.org Jochen Wiedmann
              Reporter:
              krkoska Michael Krkoska
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 5m
                5m
                Remaining:
                Remaining Estimate - 5m
                5m
                Logged:
                Time Spent - Not Specified
                Not Specified