Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Duplicate
-
3.2
-
None
-
Java 1.6.0_26
Description
CollatingIterator's javadoc (http://commons.apache.org/collections/api-release/index.html) states that natural sort ordering will be used when null is passed as the Comparator argument to any of the constructors accepting one (and for the nullary constructor). The following stack is thrown from the subsequent unit test. The implementation of least() does not appear to account for the natural sort order case.
java.lang.NullPointerException
at org.apache.commons.collections.iterators.CollatingIterator.least(CollatingIterator.java:334)
at org.apache.commons.collections.iterators.CollatingIterator.next(CollatingIterator.java:230)
at mil.af.statistics.jutl.collection.MutableDataSeriesTest...
@SuppressWarnings("unchecked")
@Test
public void testCollatingIteratorNaturalOrdering() throws Exception
{
Integer[] expected =
;
List<Integer> evens = Arrays.asList(new Integer[]
);
List<Integer> odds = Arrays.asList(new Integer[]
);
Iterator<Integer> collatingIter = new CollatingIterator(null, evens.iterator(), odds.iterator());
for (Integer expectedInt : expected)
{ assertTrue(collatingIter.hasNext()); assertEquals(expectedInt, collatingIter.next()); }}
Workaround: provide a Comparator that implements the natural ordering contract.