Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-673

ListUtils.partition potential integer overflow

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.1
    • Fix Version/s: 4.2
    • Component/s: List
    • Labels:
      None

      Description

      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:

      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);
      }
      

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                jmark John Mark
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: