Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9E5A9918F for ; Sun, 3 Jun 2012 11:21:27 +0000 (UTC) Received: (qmail 68637 invoked by uid 500); 3 Jun 2012 11:21:26 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 68348 invoked by uid 500); 3 Jun 2012 11:21:23 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 68324 invoked by uid 99); 3 Jun 2012 11:21:23 -0000 Received: from issues-vm.apache.org (HELO issues-vm) (140.211.11.160) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 03 Jun 2012 11:21:23 +0000 Received: from isssues-vm.apache.org (localhost [127.0.0.1]) by issues-vm (Postfix) with ESMTP id 24BAE140BEF for ; Sun, 3 Jun 2012 11:21:23 +0000 (UTC) Date: Sun, 3 Jun 2012 11:21:23 +0000 (UTC) From: "Thomas Neidhart (JIRA)" To: issues@commons.apache.org Message-ID: <1968720014.31585.1338722483153.JavaMail.jiratomcat@issues-vm> In-Reply-To: <650766491.1311.1311018717863.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Resolved] (COLLECTIONS-377) CollatingIterator throws NullPointerException when constructor is given null (or no) Comparator MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/COLLECTIONS-377?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Thomas Neidhart resolved COLLECTIONS-377. ----------------------------------------- Resolution: Duplicate Fix Version/s: 4.0 This has been fixed as part of [COLLECTIONS-331]. Now the javadoc states that a comparator *must* be provided (either via constructor or by calling setComparator afterwards) before using the iterator. > 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 > Fix For: 4.0 > > > 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 evens = Arrays.asList(new Integer[] > { Integer.valueOf(2), Integer.valueOf(4), Integer.valueOf(6) }); > List odds = Arrays.asList(new Integer[] > { Integer.valueOf(1), Integer.valueOf(3), Integer.valueOf(5) }); > Iterator 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. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira