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

Eric Milles edited comment on GROOVY-6151 at 1/16/22, 5:17 PM:
---------------------------------------------------------------

This method is what is used: 
{{org.codehaus.groovy.runtime.DefaultGroovyMethods#equals(Map,Map)}}

It would need to be removed or check if one of the operands implements 
{{equals}}.

This same issue could occur for any of the other extension overloads of equals:
{code:java}
public static boolean equals(List left, Object[] right)
public static boolean equals(List left, List right)
public static boolean equals(Set self, Set other)
{code}


was (Author: emilles):
This method is what is used: 
{{org.codehaus.groovy.runtime.DefaultGroovyMethods#equals(Map,Map)}}

It would need to be removed or check if one of the operands implements 
{{equals}}.

> Equal on class (extends Map)
> ----------------------------
>
>                 Key: GROOVY-6151
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6151
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.1.3
>            Reporter: Grzegorz Karawacki
>            Priority: Major
>         Attachments: Main.groovy, TestError.groovy
>
>
> The problem occurs for classes inherit from class Map:
> {code:title=TestError.groovy|borderStyle=solid}
> class TestError extends HashMap {
>     String id
>     String getId() {
>         return id
>     }
>     void setId(String id) {
>         this.id = id
>     }
>     boolean equals(Object o) {
>         if (this.is(o)) return true
>         if (getClass() != o.class) return false
>         if (!super.equals(o)) return false
>         TestError testError = (TestError) o
>         if (id != testError.id) return false
>         return true
>     }
>     int hashCode() {
>         int result = super.hashCode()
>         result = 31 * result + (id != null ? id.hashCode() : 0)
>         return result
>     }
> }
> {code}
> {code:title=Main.groovy|borderStyle=solid}
> TestError t1 = new TestError()
> t1.setId("1")
> TestError t2 = new TestError()
> t2.setId("2")
> println(t1.getId())
> println(t2.getId())
> println(t1.equals(t2))
> {code}



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

Reply via email to