[ https://issues.apache.org/jira/browse/GROOVY-5357?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jochen Theodorou resolved GROOVY-5357. -------------------------------------- Fix Version/s: 4.0.0 3.0.3 Assignee: Jochen Theodorou Resolution: Fixed Closed as fixed per user comment > The accessor pair can't be provided from different sources > ---------------------------------------------------------- > > Key: GROOVY-5357 > URL: https://issues.apache.org/jira/browse/GROOVY-5357 > Project: Groovy > Issue Type: Sub-task > Components: groovy-runtime > Reporter: OC > Assignee: Jochen Theodorou > Priority: Major > Fix For: 4.0.0, 3.0.3 > > > 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." > {code} > class Foo { > void setVal(v) { println "setVal: $v" } > } > @Category(Foo) class Getter { > def getVal() { println "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 > } > } > {code} > or > {code} > 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 > } > } > {code} > or > {code} > class Foo { > def getVal() { println "getVal" } > } > class Test { > static def main(av) { > Foo.metaClass.setVal={v-> } > def f = new Foo() > f.getVal() > f.val > } > } > {code} > etc. -- This message was sent by Atlassian Jira (v8.20.10#820010)