groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject groovy git commit: GROOVY-6958 null != NullObject when using categories Closes #207
Date Sat, 16 Jan 2016 22:21:54 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 7a2baa556 -> 32706bf7e


GROOVY-6958 null != NullObject when using categories
Closes #207


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/32706bf7
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/32706bf7
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/32706bf7

Branch: refs/heads/GROOVY_2_4_X
Commit: 32706bf7eead9710e3aa314426eb8fbe643cef64
Parents: 7a2baa5
Author: Shil Sinha <shils@apache.org>
Authored: Wed Dec 9 00:03:43 2015 -0500
Committer: Shil Sinha <shils@apache.org>
Committed: Sat Jan 16 17:17:33 2016 -0500

----------------------------------------------------------------------
 .../typehandling/DefaultTypeTransformation.java     |  3 ++-
 .../codehaus/groovy/runtime/NullObjectTest.groovy   | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/32706bf7/src/main/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
b/src/main/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
index 1742330..95ddc00 100644
--- a/src/main/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
+++ b/src/main/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
@@ -602,7 +602,8 @@ public class DefaultTypeTransformation {
 
     public static boolean compareEqual(Object left, Object right) {
         if (left == right) return true;
-        if (left == null || right == null) return false;
+        if (left == null) return right instanceof NullObject;
+        if (right == null) return left instanceof NullObject;
         if (left instanceof Comparable) {
             return compareToWithEqualityCheck(left, right, true) == 0;
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/32706bf7/src/test/org/codehaus/groovy/runtime/NullObjectTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/runtime/NullObjectTest.groovy b/src/test/org/codehaus/groovy/runtime/NullObjectTest.groovy
index a7afa06..05ad71d 100644
--- a/src/test/org/codehaus/groovy/runtime/NullObjectTest.groovy
+++ b/src/test/org/codehaus/groovy/runtime/NullObjectTest.groovy
@@ -100,11 +100,27 @@ class NullObjectTest extends GroovyTestCase {
         }
         assert a == 2
     }
+
+    void testEqualsInCategory() {
+        def val = null
+        use (MyCategory) {
+            assert val.isNull()
+            assert val.isNull2()
+        }
+    }
 }
 
 class MyCategory {
     public static String toString(NullObject obj) {
         return ""
     }
+
+    static boolean isNull(value) {
+        value == null
+    }
+
+    static boolean isNull2(value) {
+        null == value
+    }
 }
 


Mime
View raw message