You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2022/03/08 12:17:01 UTC
[jira] [Closed] (GROOVY-6176) List substraction doesn't work correctly with objects that have the same hash code
[ https://issues.apache.org/jira/browse/GROOVY-6176?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-6176.
-----------------------------
> 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)