[ 
https://issues.apache.org/jira/browse/GROOVY-5491?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17470688#comment-17470688
 ] 

Eric Milles commented on GROOVY-5491:
-------------------------------------

[~paulk]  I'd expect get and set to be aligned.  In light of this and 
GROOVY-5001, would you expect Map#get to have lower precedence or Map#put to 
have higher precedence?

> HashMap subclass property access inconsistent
> ---------------------------------------------
>
>                 Key: GROOVY-5491
>                 URL: https://issues.apache.org/jira/browse/GROOVY-5491
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 1.8.6
>            Reporter: Michael Collado
>            Assignee: Eric Milles
>            Priority: Minor
>
> Creating a subclass of java.util.HashMap with properties defined results in 
> inconsistent and confusing behavior. 
> {code:java}
> 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'
> {code}
> 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.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to