Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.12
-
None
-
None
Description
Problem: Adding the private keyword causes a difference in behavior when using the dot operator
Consider the following 2 scripts with the same class (1 with the instance variable declared as private with everything else being the same)
Script 1:
import java.util.concurrent.ConcurrentHashMap import groovy.transform.CompileStatic class mymap<K,V> extends ConcurrentHashMap<K,V>{ private String a = 'a'; def cloned(){ def clone = new mymap<K,V>() clone.putAll(this) clone.a = this.a return clone } } def mm = new mymap<String, String>() def fieldA = mymap.class.getDeclaredField("a") fieldA.setAccessible(true) mm.b = 'b' def cloned = mm.cloned() println(cloned.a) println(fieldA.get(cloned)) println(cloned)
Output:
a a [a:a, b:b]
Script 2:
import java.util.concurrent.ConcurrentHashMap import groovy.transform.CompileStatic class mymap<K,V> extends ConcurrentHashMap<K,V>{ String a = 'a'; def cloned(){ def clone = new mymap<K,V>() clone.putAll(this) clone.a = this.a return clone } } def mm = new mymap<String, String>() def fieldA = mymap.class.getDeclaredField("a") fieldA.setAccessible(true) mm.b = 'b' def cloned = mm.cloned() println(cloned.a) println(fieldA.get(cloned)) println(cloned)
Output:
null
a
[b:b]
Expectation
Adding the 'private' keyword in front of the instance variable should not change the output of these 2 scripts
Attachments
Issue Links
- is related to
-
GROOVY-5001 Map access is given higher precedence when trying to access fields/properties in classes which implement java.util.Map or extend java.util.HashMap or java.util.Properties
- Closed
- relates to
-
GROOVY-11403 property semantics of map-based types (pt.2)
- Closed