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

Eric Milles resolved GROOVY-6176.
---------------------------------
    Resolution: Fixed

Works fine in Groovy 2.5+

> List substraction doesn't work correctly with objects that have the same hash 
> code
> ----------------------------------------------------------------------------------
>
>                 Key: GROOVY-6176
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6176
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.1.1, 2.1.3
>            Reporter: Mikhail Chivozertsev
>            Priority: Major
>
> During list substraction groovy removes elements with the same hash code. But 
> it has to remove equal elements. (It is obviously that sometimes non equal 
> elements can have the same hash code)
> {code}
> class MyClass {
>  int value = 0
>  boolean equals(o) {
>   if (o instanceof MyClass && value == o.value) return true
>   return false
>  }
>  int hashCode() {
>   return 1
>  }
> }
> def o1 = new MyClass(value:1)
> def o2 = new MyClass(value:2)
> def o3 = new MyClass(value:3)
> def list = [o1, o2]
> def result = list - [o3]
> assert result == [] // it looks strange, I think
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to