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 2021/03/30 17:10:00 UTC

[jira] [Updated] (GROOVY-9851) Private field and method use from subclass is inconsistent

     [ https://issues.apache.org/jira/browse/GROOVY-9851?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles updated GROOVY-9851:
--------------------------------
    Description: 
This is probably just a slice of GROOVY-1591, GROOVY-3010, GROOVY-3142, GROOVY-5438, et al.

Adding {{super.}} qualifier causes strange behaviors. Consider the following:
{code:java}
class Foo {
  private String field = 'field'
  private String method() { 'method' }
}
class Bar extends Foo {
  def baz() {
    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()

    super.@field // MissingFieldException: No such field: field for class: Bar -- fixed by GROOVY-8999

    // 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.&method)() // MissingMethodException: No signature of method: Bar.method() is applicable for argument types: () values: []
  }
}
{code}

  was:
This is probably just a slice of GROOVY-1591, GROOVY-3010, GROOVY-3142, GROOVY-5438, et al. Adding {{super.}} qualifier causes strange behaviors. Consider the following:
{code:java}
class Foo {
  private String field = 'field'
  private String method() { 'method' }
}
class Bar extends Foo {
  def baz() {
    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()

    super.@field // MissingFieldException: No such field: field for class: Bar -- fixed by GROOVY-8999

    // 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.&method)() // MissingMethodException: No signature of method: Bar.method() is applicable for argument types: () values: []
  }
}
{code}


> Private field and method use from subclass is inconsistent
> ----------------------------------------------------------
>
>                 Key: GROOVY-9851
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9851
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Eric Milles
>            Priority: Minor
>
> This is probably just a slice of GROOVY-1591, GROOVY-3010, GROOVY-3142, GROOVY-5438, et al.
> Adding {{super.}} qualifier causes strange behaviors. Consider the following:
> {code:java}
> class Foo {
>   private String field = 'field'
>   private String method() { 'method' }
> }
> class Bar extends Foo {
>   def baz() {
>     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()
>     super.@field // MissingFieldException: No such field: field for class: Bar -- fixed by GROOVY-8999
>     // 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.&method)() // MissingMethodException: No signature of method: Bar.method() is applicable for argument types: () values: []
>   }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)