You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2019/02/18 18:13:00 UTC

[jira] [Created] (GROOVY-8999) Access to private fields and methods from subclass exhibits strange behavior

Eric Milles created GROOVY-8999:
-----------------------------------

             Summary: Access to private fields and methods from subclass exhibits strange behavior
                 Key: GROOVY-8999
                 URL: https://issues.apache.org/jira/browse/GROOVY-8999
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 2.4.16
            Reporter: Eric Milles


This is probably just a slice of GROOVY-1591, GROOVY-3010, GROOVY-3142, GROOVY-5438, et al. Adding {{super.}} qualifier causes strange behaviors. Please consider the following:
{code}
class Foo {
  private String field = 'field'
  private String method() { 'method' }
}
class Bar extends Foo {
  void meth() {
    field // MissingPropertyException: No such property: field for class: Bar
    method() // MissingMethodException: No signature of method: Bar.method()
    this.field // MissingPropertyException: No such property: field for class: Bar
    this.method() // MissingMethodException: No signature of method: Bar.method()

    // so far, so good -- although Groovy allows access to private fields and methods from outside of Bar and Foo

    super.field // MissingMethodException: No signature of method: Bar.getField() -- that's strange
    super.method() // returns "method" -- Why is this okay?

    super.@field //  // MissingMethodException: No signature of method: Bar.getField() -- that's strange
  super.&method // returns null -- If super.method() works, why does this not return the method reference?
  }
}
{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)