isEqualSet method in SetUtils could rehash the two input sets before it does 
the containsAll comparison
-------------------------------------------------------------------------------------------------------

                 Key: COLLECTIONS-311
                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-311
             Project: Commons Collections
          Issue Type: Improvement
          Components: Set
    Affects Versions: 3.2
            Reporter: Michael Qiu


Hey Guys

I had an interesting problem recently where I was comparing 2 sets and the 
equals method was returning false... maybe it might be easier to understand if 
I explain using pseudo code:
{code}
set1.equals(set2) = false
set1.get(0).equals(set2.get(0)) = true
set1.get(1).equals(set2.get(1)) = true
set1.get(0).hashCode() == set2.get(0).hashCode() = true
set1.get(1).hashCode() == set2.get(1).hashCode() = true
{code}
So, objects in the two sets are equals, the hashCode of the objects in the two 
sets are equals, however the equals comparison at the set level was not equals. 
 

After some time, we figured out that the problem was that the object inside the 
set was getting modified after it was put into the set.  So the new hashCode of 
the object has changed.  However the bucket of the set that it's in hasn't 
changed.  When another piece of code calls the contains method, it looks for 
the equivalent object in a bucket according to the new hashCode.  When it 
doesn't find it, and it returns false.  

I would like to suggest that the SetUtils.isEqualSet method rehashes contents 
of the sets given in the parameters before it does the containsAll comparison 
to avoid the problem caused by this scenario.  


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to