You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/12/03 20:30:13 UTC
[groovy] branch GROOVY_3_0_X updated: GROOVY-10398: LazyFieldNode never equals itself
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
new bf0ad84 GROOVY-10398: LazyFieldNode never equals itself
bf0ad84 is described below
commit bf0ad84358045c0fc56458e7af57ef198b8a1a6f
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed Dec 1 14:15:44 2021 +1000
GROOVY-10398: LazyFieldNode never equals itself
---
.../java/org/codehaus/groovy/ast/FieldNode.java | 8 +++++
.../groovy/ast/decompiled/LazyFieldNode.java | 1 +
.../ast/decompiled/FieldNodeEqualityTest.groovy | 40 ++++++++++++++++++++++
3 files changed, 49 insertions(+)
diff --git a/src/main/java/org/codehaus/groovy/ast/FieldNode.java b/src/main/java/org/codehaus/groovy/ast/FieldNode.java
index 28208cd..0681c41 100644
--- a/src/main/java/org/codehaus/groovy/ast/FieldNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/FieldNode.java
@@ -191,6 +191,14 @@ public class FieldNode extends AnnotatedNode implements Opcodes, Variable {
}
@Override
+ public boolean equals(Object obj) {
+ if (obj != null && obj.getClass().getName().equals("org.codehaus.groovy.ast.decompiled.LazyFieldNode")) {
+ return obj.equals(this);
+ }
+ return super.equals(obj);
+ }
+
+ @Override
public ClassNode getOriginType() {
return originType;
}
diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/LazyFieldNode.java b/src/main/java/org/codehaus/groovy/ast/decompiled/LazyFieldNode.java
index 49eb7fa..c995441 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/LazyFieldNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/LazyFieldNode.java
@@ -396,6 +396,7 @@ class LazyFieldNode extends FieldNode implements LazyInitializable {
@Override
public boolean equals(Object obj) {
+ if (obj == this) return true;
lazyInit();
return delegate.equals(obj);
}
diff --git a/src/test/org/codehaus/groovy/ast/decompiled/FieldNodeEqualityTest.groovy b/src/test/org/codehaus/groovy/ast/decompiled/FieldNodeEqualityTest.groovy
new file mode 100644
index 0000000..8051628
--- /dev/null
+++ b/src/test/org/codehaus/groovy/ast/decompiled/FieldNodeEqualityTest.groovy
@@ -0,0 +1,40 @@
+/*
+ * 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.decompiled
+
+import org.codehaus.groovy.ast.FieldNode
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.junit.Test
+
+final class FieldNodeEqualityTest {
+ @Test
+ void testEquality() {
+ FieldNode fn1 = FieldNode.newStatic(CompilerConfiguration, 'JDK11')
+ assert fn1.equals(fn1)
+ FieldNode fn2 = new LazyFieldNode(() -> fn1, 'JDK11')
+ assert fn1.equals(fn2)
+ assert fn2.equals(fn1)
+ assert fn2.equals(fn2)
+
+ List nodes1 = [fn1]
+ assert nodes1.contains(fn1)
+ List nodes2 = [fn2]
+ assert nodes2.contains(fn2)
+ }
+}