Details
-
Type:
Sub-task
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
When one of the accessor pair is added through a mixin or metaclass, Groovy behaves as if the other one did not exist.
Explanation kindly provided by Paul: "MetaClassImpl finds a MetaBeanProperty containing just the getter. When only a getter is found there is an incorrect assumption that a setter doesn't exist in the underlying class."
===
class Foo {
void setVal(v)
}
@Category(Foo) class Getter {
def getVal()
}
class Test {
static def main(av) { Foo.mixin Getter def f = new Foo() f.setVal('foo') f.val = null // => groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: val for class: Foo }
}
===
or
===
class Foo {
void setVal(v) { println "setVal: $v" }
}
class Test {
static def main(av) {
Foo.metaClass.getVal={-> println "getval" }
def f = new Foo()
f.setVal('foo')
f.val = null // => groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: val for class: Foo
}
}
===
or
===
class Foo {
def getVal() { println "getVal" }
}
class Test {
static def main(av) {
Foo.metaClass.setVal=
def f = new Foo()
f.getVal()
f.val
}
}
===
etc.
I guess this is something for 3.0?