Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.5.7
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Number of attachments :
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.
Issue Links
- is duplicated by
-
GROOVY-4083
private members should be accessible in closures used from sub classes
-
-
GROOVY-4084
Private class property not visible from closure in a super. invoked method
-
- relates to
-
GROOVY-3010
fix private field visibility
-
Note that this also fails :
class B { private String data B(arg) { arg.each() { data = it } } } class C extends B { C(arg) { super(arg) } } new C(["test"])