You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/05/28 01:12:23 UTC

[groovy] 02/02: GROOVY-9575

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 1e93451821732a6d34b0e3b369e27dea59370368
Author: Anders Wallgren <aw...@cloudbees.com>
AuthorDate: Tue May 26 19:18:37 2020 -0700

    GROOVY-9575
    
    Remove unsuitable ASTNode.hashCode -- it does not conform to the Object
    .hashCode general contract.
    
    (cherry picked from commit eb8539f45daf1b980b99ddd824cb05ed2e14cc1f)
---
 src/main/java/org/codehaus/groovy/ast/ASTNode.java |  6 ----
 src/test/org/codehaus/groovy/ast/ASTNodeTest.java  | 33 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/ASTNode.java b/src/main/java/org/codehaus/groovy/ast/ASTNode.java
index 39b9f8c..66ccecf 100644
--- a/src/main/java/org/codehaus/groovy/ast/ASTNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/ASTNode.java
@@ -18,7 +18,6 @@
  */
 package org.codehaus.groovy.ast;
 
-import java.util.Arrays;
 import java.util.Map;
 
 /**
@@ -121,9 +120,4 @@ public class ASTNode implements NodeMetaDataHandler {
     public void setMetaDataMap(Map<?, ?> metaDataMap) {
         this.metaDataMap = metaDataMap;
     }
-
-    @Override
-    public int hashCode() {
-        return Arrays.hashCode(new int[] {lineNumber, columnNumber, lastLineNumber, lastColumnNumber});
-    }
 }
diff --git a/src/test/org/codehaus/groovy/ast/ASTNodeTest.java b/src/test/org/codehaus/groovy/ast/ASTNodeTest.java
new file mode 100644
index 0000000..cb2b60e
--- /dev/null
+++ b/src/test/org/codehaus/groovy/ast/ASTNodeTest.java
@@ -0,0 +1,33 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.ast;
+
+import junit.framework.TestCase;
+
+public class ASTNodeTest extends TestCase {
+
+    ASTNode astNode = new ASTNode();
+
+    public void testHashCode() {
+        int hashcode = astNode.hashCode();
+        
+        astNode.setLineNumber(astNode.getLineNumber() + 10);
+        assertEquals("hashCode is consistent", hashcode, astNode.hashCode());
+    }
+}