groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Milles (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-8999) Access to private fields and methods from subclass exhibits strange behavior
Date Mon, 18 Feb 2019 18:18:00 GMT

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

Eric Milles updated GROOVY-8999:
--------------------------------
    Description: 
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: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()

    // 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 MethodClosure that throws NPE when called:
    (super.&method)() // NullPointerException: Cannot invoke method call() on null object--
If super.method() works, why doesn't this?
  }
}
{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. Please 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()

    // 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}


> 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
>            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. Please 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()
>     // 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 MethodClosure that throws NPE when called:
>     (super.&method)() // NullPointerException: Cannot invoke method call() on null
object-- If super.method() works, why doesn't this?
>   }
> }
> {code}



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

Mime
View raw message