Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
class B { String data B(arg) { arg.each() { this.@data = it } } } class C extends B { C(arg) { super(arg) } } new C(["test"])
The previous unexpectedly produce: Exception thrown: groovy.lang.MissingFieldException: No such field: data for class: C
class B { private String data public String getData() { this.@data } private setData(String value) { this.@data = value } B(arg) { arg.each() { data = it } } } class C extends B { C(arg) { super(arg) } } new C(["test"])
And this one produce a similar issue: Exception thrown: groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: data for class: C
Both is related to the fact that the closure is routed throught C and not B which is the expectation. In the second sample, providing a protected setter is a workaround.
Attachments
Issue Links
- is duplicated by
-
GROOVY-4083 private members should be accessible in closures used from sub classes
- Closed
-
GROOVY-4084 Private class property not visible from closure in a super. invoked method
- Closed
- is related to
-
GROOVY-3073 Private inheritance bug: Closure accessing private method
- Closed
-
GROOVY-5438 Private field inaccessible in closure when using a subclass
- Closed
- relates to
-
GROOVY-3010 fix private field visibility
- Open