You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "John Mark (JIRA)" <ji...@apache.org> on 2018/02/02 17:19:00 UTC

[jira] [Created] (COLLECTIONS-673) ListUtils.partition potential integer overflow

John Mark created COLLECTIONS-673:
-------------------------------------

             Summary: ListUtils.partition potential integer overflow
                 Key: COLLECTIONS-673
                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-673
             Project: Commons Collections
          Issue Type: Bug
          Components: List
    Affects Versions: 4.1
            Reporter: John Mark


When calling {{ListUtils.partition()}} with a large size and large list, it is possible that an integer overflow will occur in the {{size()}} method that causes incorrect behavior. This will occur when using a size that, when added to list.size() will be larger than {{Integer.MAX_VALUE}}

Current version of Guava's {{Lists.partition()}} handle this correctly, so perhaps the code for {{ListUtils.partition()}} needs to be updated based on the latest Guava code.

A simple illustration of this:
{code}
List<String> aList = Arrays.asList("1", "2", "3", "4", "5");
List<List<String>> partitioned = ListUtils.partition(aList, Integer.MAX_VALUE);
System.out.println("Number of partitions: " + partitioned.size());
for(List<String> l : partitioned)  {
     System.out.println(l);
}
{code}

The above code works correctly when using Guava's {{Lists.partition()}} instead.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)