You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Thomas Neidhart (JIRA)" <ji...@apache.org> on 2013/12/22 21:06:50 UTC

[jira] [Commented] (COLLECTIONS-506) Result of CollecrionUtils are different between version 3.2.1 and version 4.0

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

Thomas Neidhart commented on COLLECTIONS-506:
---------------------------------------------

I could not yet test your example but looking at the source of ObjectTest it looks like you did not implement hashCode properly.

As the subtract method puts the items in a HashBag it is absolutely necessary that you follow the contract for Object#equals (see http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals%28java.lang.Object%29) for more details.

> Result of CollecrionUtils are different between version 3.2.1 and version 4.0
> -----------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-506
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-506
>             Project: Commons Collections
>          Issue Type: Bug
>    Affects Versions: 4.0
>            Reporter: Anthony Communier
>         Attachments: test-common-collection.zip
>
>
> 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



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)