commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ryan Hochstetler (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (COLLECTIONS-377) CollatingIterator throws NullPointerException when constructor is given null (or no) Comparator
Date Mon, 18 Jul 2011 19:57:57 GMT

     [ https://issues.apache.org/jira/browse/COLLECTIONS-377?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Ryan Hochstetler updated COLLECTIONS-377:
-----------------------------------------

    Priority: Minor  (was: Major)

Setting priority, as I forgot to set it originally, and it defaulted to Major.

> CollatingIterator throws NullPointerException when constructor is given null (or no)
Comparator
> -----------------------------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-377
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-377
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Iterator
>    Affects Versions: 3.2
>         Environment: Java 1.6.0_26
>            Reporter: Ryan Hochstetler
>            Priority: Minor
>
> 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 =
>         { Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4),
Integer.valueOf(5),
>             Integer.valueOf(6) };
>         List<Integer> evens = Arrays.asList(new Integer[]
>         { Integer.valueOf(2), Integer.valueOf(4), Integer.valueOf(6) });
>         List<Integer> odds = Arrays.asList(new Integer[]
>         { Integer.valueOf(1), Integer.valueOf(3), Integer.valueOf(5) });
>         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.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message