groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwagenleit...@apache.org
Subject groovy git commit: GROOVY-5985 - Invalid hash key serialVersionUID (closes #365)
Date Sat, 23 Jul 2016 00:47:12 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 9ff17a494 -> bd8242fb9


GROOVY-5985 - Invalid hash key serialVersionUID (closes #365)

Using a map key with the same name as a read-only property on the Map
class would throw a groovy.lang.ReadOnlyPropertyException.  The fix for
GROOVY-3471 (commit 18f6f8271ed3bfb) moved the map handling
below the handling for read-only properties.  In order to avoid the
issue in GROOVY-3471 we also need to check and make sure the
method is null so we are not in a setX call.


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

Branch: refs/heads/GROOVY_2_4_X
Commit: bd8242fb9d0717b33e5f294905ddc87002c99962
Parents: 9ff17a4
Author: John Wagenleitner <jwagenleitner@apache.org>
Authored: Fri Jul 22 17:16:04 2016 -0700
Committer: John Wagenleitner <jwagenleitner@apache.org>
Committed: Fri Jul 22 17:26:30 2016 -0700

----------------------------------------------------------------------
 src/main/groovy/lang/MetaClassImpl.java | 16 +++++++-------
 src/test/groovy/MapPropertyTest.groovy  | 33 ++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/bd8242fb/src/main/groovy/lang/MetaClassImpl.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/MetaClassImpl.java b/src/main/groovy/lang/MetaClassImpl.java
index 8ec2903..3c49a33 100644
--- a/src/main/groovy/lang/MetaClassImpl.java
+++ b/src/main/groovy/lang/MetaClassImpl.java
@@ -2659,6 +2659,14 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
         }
 
         //----------------------------------------------------------------------
+        // turn setProperty on a Map to put on the Map itself
+        //----------------------------------------------------------------------
+        if (method == null && !isStatic && this.isMap) {
+            ((Map) object).put(name, newValue);
+            return;
+        }
+
+        //----------------------------------------------------------------------
         // field
         //----------------------------------------------------------------------
         if (method == null && field != null) {
@@ -2707,14 +2715,6 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
         }
 
         //----------------------------------------------------------------------
-        // turn setProperty on a Map to put on the Map itself
-        //----------------------------------------------------------------------
-        if (!isStatic && this.isMap) {
-            ((Map) object).put(name, newValue);
-            return;
-        }
-
-        //----------------------------------------------------------------------
         // error due to missing method/field
         //----------------------------------------------------------------------
         if (ambiguousListener) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/bd8242fb/src/test/groovy/MapPropertyTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/MapPropertyTest.groovy b/src/test/groovy/MapPropertyTest.groovy
index 1295a14..3176145 100644
--- a/src/test/groovy/MapPropertyTest.groovy
+++ b/src/test/groovy/MapPropertyTest.groovy
@@ -61,6 +61,34 @@ class MapPropertyTest extends GroovyTestCase {
         assert c.class == 1
         assert c.getClass() != 1
     }
+
+    // GROOVY-5985
+    void testMapPutAtWithKeyMatchingReadOnlyProperty() {
+        def map = [serialVersionUID:123]
+        assert map["serialVersionUID"] == 123
+        assert map.serialVersionUID == 123
+
+        map.put("serialVersionUID", 789)
+        assert map["serialVersionUID"] == 789
+        assert map.serialVersionUID == 789
+
+        map.putAt("serialVersionUID", 333)
+        assert map.serialVersionUID == 333
+
+        map = new MyMapClassWithReadOnlyProperties()
+
+        assert map['classVar'] == null
+        assert map.@classVar == 'class var'
+
+        map['classVar'] = 'map var'
+        assert map['classVar'] == 'map var'
+
+        assert map['instanceVar'] == null
+        assert map.@instanceVar == 77
+
+        map['instanceVar'] = 42
+        assert map['instanceVar'] == 42
+    }
 }
 
 class MyClass extends HashMap {
@@ -69,3 +97,8 @@ class MyClass extends HashMap {
         assert this.class == 1
     }
 }
+
+class MyMapClassWithReadOnlyProperties extends HashMap {
+    private static final String classVar = 'class var'
+    private final int instanceVar = 77
+}


Mime
View raw message