jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-3142

Unable to access inherited private fields from a closure within an inherited method

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.5.7
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    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.

Issue Links

is duplicated by

Bug - A problem which impairs or prevents the functions of the product. GROOVY-4083 private members should be accessible in closures used from sub classes

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Bug - A problem which impairs or prevents the functions of the product. GROOVY-4084 Private class property not visible from closure in a super. invoked method

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.
relates to

Task - A task that needs to be done. GROOVY-3010 fix private field visibility

  • Major - Major loss of function.
  • Open - The issue is open and ready for the assignee to start work on it.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Denis Gervalle added a comment - 10/Nov/08 10:59 AM

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"])
Show
Denis Gervalle added a comment - 10/Nov/08 10:59 AM 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"])
Hide
Permalink
Denis Gervalle added a comment - 04/May/10 12:30 AM

Here another sample that is not working properly until you either change private to protected on the getValue() method, or use new A() instead of new B():

public class A {
    private int getValue() {
        return 1;
    }
    public void printValue() {
        println value.toString();
    }
}

public class B extends A {
}

A a = new B();
a.printValue();
Show
Denis Gervalle added a comment - 04/May/10 12:30 AM Here another sample that is not working properly until you either change private to protected on the getValue() method, or use new A() instead of new B():
public class A {
    private int getValue() {
        return 1;
    }
    public void printValue() {
        println value.toString();
    }
}

public class B extends A {
}

A a = new B();
a.printValue();

People

  • Assignee:
    Unassigned
    Reporter:
    Denis Gervalle
Vote (1)
Watch (2)

Dates

  • Created:
    10/Nov/08 10:50 AM
    Updated:
    04/May/10 12:30 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.