You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Henri Yandell (JIRA)" <ji...@apache.org> on 2010/03/26 07:36:27 UTC

[jira] Commented: (COLLECTIONS-331) CollatingIterator NPE when Comparator is null

    [ https://issues.apache.org/jira/browse/COLLECTIONS-331?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12850022#action_12850022 ] 

Henri Yandell commented on COLLECTIONS-331:
-------------------------------------------

Confirm on the bug. 

Issue is that ComparableComparator can't be used if the objects aren't Comparable.

Now that things are generified this won't even compile. Specifically this is that CollatingIterator<E> and ComparableComparator<E extends Comparable<? super E>> don't match.

One option would be to throw exception if not comparable, but use comparable comparator if E is comparable.

> CollatingIterator NPE when Comparator is null
> ---------------------------------------------
>
>                 Key: COLLECTIONS-331
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-331
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Iterator
>    Affects Versions: 3.2
>            Reporter: Michael Krkoska
>            Priority: Minor
>             Fix For: 4.0-beta-1
>
>         Attachments: CollatingIteratorTest.java, COLLECTIONS-331.patch
>
>   Original Estimate: 0.08h
>  Remaining Estimate: 0.08h
>
> 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()}}: 
> {code}
> if (comparator.compare(curObject,leastObject) < 0) { ...
> {code}
> could be replaced with
> {code}
> int c = comparator==null?((Comparable)curObject).compareTo(leastObject):comparator.compare(curObject,leastObject);
> if (c < 0) { ...
> {code}
> The workaround is to provide a comparator, of course.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.