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

4 messages Options
Embed this post
Permalink
JIRA jira@apache.org

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

Reply Threaded More More options
Print post
Permalink
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


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.

JIRA jira@apache.org

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

Reply Threaded More More options
Print post
Permalink

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

Michael Krkoska updated COLLECTIONS-331:
----------------------------------------

    Attachment: CollatingIteratorTest.java

JUnit4 Testcase showing bug

> 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
>         Attachments: CollatingIteratorTest.java
>
>   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.

JIRA jira@apache.org

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

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

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

Michael Krkoska updated COLLECTIONS-331:
----------------------------------------

    Attachment: COLLECTIONS-331.patch

This patch fixes the bug by using ComparableComparator if the comparator is null.
Testcase is adapted as well.

> 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
>         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.

JIRA jira@apache.org

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

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

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

Henri Yandell updated COLLECTIONS-331:
--------------------------------------

    Fix Version/s: 3.3

> 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: 3.3
>
>         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.