Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.8.6
-
None
Description
Creating a subclass of java.util.HashMap with properties defined results in inconsistent and confusing behavior.
class MapSub extends HashMap { def foo } // Using dot notation to get the property results in a map key lookup. def m = new MapSub(foo: 'bar') println m.foo // prints 'null' println m.getFoo() // prints 'bar' // Using same dot notation to set the property results in property setter. m.foo = 'baz' println m.foo // still prints 'null' println m.getFoo() // prints 'baz'
This behavior results in subtle and hard to track bugs. I saw another Jira that stated that a design decision was made that Map dot property getters always resulted in a map key lookup. For consistency, I think either the same policy should be applied to Map property setters or the original design decision should be reconsidered to first check for property existence.
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