|
[
Permalink
| « Hide
]
Eric McIntyre added a comment - 30/May/07 02:08 PM
In the attached script I have tried extending AbstractMap, HashMap, and LinkedHashMap – all of which exhibited the same behavior unless get() was implemented. I also tried extending other classes, like AbstractList, Random, and Button, and implementing Map directly, but these worked.
It's also important to note that this script runs fine in Groovy 1.0. It breaks with 1.1 Beta 1 and above (tested with beta 1 and a very recent beta 2 snapshot build from Canoo, 20070529165022).
hmm... when you replace "var" with this.@var, then all is fine...
after looking at this closely I will close it with "Won't Fix"
In your code def doIt() {
assert 'o' == var.substring(1, 2)
def c = { assert 'o' == var.substring(1, 2) }
c()
}
the first line succeeds the closure fails. the reason is that in a closure getProperty is always used and since this is a Map, the map contents are used which means var is null. I see two basic ways out of it... First use "this.@var.substring(1, 2) }" in the closure. You will then access the attribute directly. Next version is to remove "def var='foo'" and instead write a constructor with "var='foo'". Then var will be set in the map with the value "foo" and accessing it will not cause a NPE. |
|||||||||||||||||||||||||||||||||||||||||||||||