[ 
https://issues.apache.org/jira/browse/GROOVY-7158?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

John Wagenleitner closed GROOVY-7158.
-------------------------------------
    Resolution: Fixed
      Assignee: John Wagenleitner

This issue was fixed by the fix for GROOVY-7530 and the [code in 
question|https://github.com/apache/groovy/blob/6a8232a5ba4fdf89c7c3d1eddba68b909f4a732a/src/main/org/codehaus/groovy/runtime/NumberAwareComparator.java#L53]
 now compares using {{equals}}.


> minus(List, Collection) considers different objects equal if they have equal 
> hashCodes
> --------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7158
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7158
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk
>            Reporter: motto
>            Assignee: John Wagenleitner
>
> This is essentially a duplicate of GROOVY-4101 and the related ticket 
> GROOVY-4124.
> In [org.codehaus.groovy.runtime.DefaultGroovyMethods.minus(Collection<T> 
> self, Collection<?> 
> removeMe)|https://github.com/groovy/groovy-core/blob/master/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L10048]
> {noformat}
> Comparator<T> numberComparator = new NumberAwareComparator<T>();
> ...
> if (numberComparator.compare(element, (T)elt) == 0) {
>   iter.remove();
>   elementRemoved = true;
> }
> {noformat}
> objects not implementing 
> [Comparable|http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html]
>  and without a compareTo method are compared using the 
> [NumberAwareComparator|https://github.com/groovy/groovy-core/blob/master/src/main/org/codehaus/groovy/runtime/NumberAwareComparator.java#L37]
> {noformat}
>  // since the object does not have a valid compareTo method
> // we compare using the hashcodes. null cases are handled by
> // DefaultTypeTransformation.compareTo
> int x1 = o1.hashCode();
> int x2 = o2.hashCode();
> if (x1 == x2) return 0;
> if (x1 < x2) return -1;
> return 1;
> {noformat}
> which incorrectly removes unequal objects from the original collection.
> This is exceedingly frustrating because the results are therefore sporadic 
> and supposedly resolved according to GROOVY-4101 and GROOVY-4124. After a 
> fair amount of head scratching and debugging (on more than 1 occasion) I went 
> looking at the sources on github and it appears the patch has never made it 
> into master. Is it possible the patch was deemed unfit? Was it forgotten 
> about? Is this something I should fix myself?



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to