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

Result of CollectionUtils are different between version 3.2.1 and version 4.0

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0
    • 4.1
    • None
    • None

    Description

      CollectionUtils V3 uses equals to compute results but not CollectionUtils v4 (it seems to use ==)

      The following exemple with subtract method :

      List<ObjectTest> listA = new ArrayList<ObjectTest>();
      List<ObjectTest> listB = new ArrayList<ObjectTest>();

      listA.add(new ObjectTest("Test1"));
      listA.add(new ObjectTest("Test2"));
      listA.add(new ObjectTest("Test3"));

      listB.add(new ObjectTest("Test1"));
      listB.add(new ObjectTest("Test2"));

      Collection<?> res1 = org.apache.commons.collections.CollectionUtils.subtract(listA, listB);
      System.out.println("Res1 size = " +res1.size());
      Collection<?> res2 = org.apache.commons.collections4.CollectionUtils.subtract(listA, listB);
      System.out.println("Res2 size = " +res2.size());

      Produces this :
      Res1 size = 1
      Res2 size = 3

      The new behaviour is not useful. It would be better to have the V3 behaviour

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            anthonyC Anthony Communier
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment