[
https://issues.apache.org/jira/browse/GROOVY-12675?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18137463#comment-18137463
]
ASF GitHub Bot commented on GROOVY-12675:
-----------------------------------------
codeconsole opened a new pull request, #3196:
URL: https://github.com/apache/groovy/pull/3196
A missing property on a closure suggested a private field of `Closure`:
```groovy
def c = { -> 1 }
c.metaClass.getProperty(c, 'bar')
// No such property: bar for class: ...$_run_closure1
// Possible solutions: bcw
```
Seen in 4.0.33, 5.0.8 and 6.0.0 too.
`MethodRankHelper.getPropertySuggestionString` ranks the properties of the
class's metaclass. For a closure class that is `ClosureMetaClass`, and its
`getProperties` returned the property list of the metaclass of `Closure`
itself. That list includes Closure's own private members (`bcw`,
`serialVersionUID`, `thisType`, `PROPERTY_GETTERS`, ...). A closure class is a
subclass of `Closure` and does not inherit them, and the metaclass of any other
subclass already leaves superclass private fields out.
`ClosureMetaClass.getProperties` now drops private entries. Properties with
a public getter or setter (`directive`, `owner`, ...) and the public constants
stay listed, so `directiv` still suggests `directive`. Suggestions for ordinary
classes are unchanged.
## Tests
`Groovy6260.testErrorMessage5` and
`ClosureTest.testGetPropertiesExcludesPrivateMembersOfClosure` fail without the
change. The `groovy.lang.*`, `org.codehaus.groovy.runtime.*`,
`groovy.*Closure*`, `groovy.PropertyTest`, `bugs.*` and `groovy.json.*` tests
pass. The Checkstyle and CodeNarc gates pass.
> MissingPropertyException for a closure suggests the private field Closure.bcw
> -----------------------------------------------------------------------------
>
> Key: GROOVY-12675
> URL: https://issues.apache.org/jira/browse/GROOVY-12675
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.33, 5.0.8, 7.0.0-alpha-1, 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> def c = { -> 1 }
> c.metaClass.getProperty(c, 'bar')
> {code}
> *Actual:*
> {noformat}
> groovy.lang.MissingPropertyException: No such property: bar for class:
> Script1$_run_closure1
> Possible solutions: bcw
> {noformat}
> In the same way, {{thisTyp}} suggests {{thisType}} and {{serialVersionUI}}
> suggests {{serialVersionUID}}. {{c.metaClass.properties}} lists these and the
> other private members of {{groovy.lang.Closure}}.
> *Expected:* no suggestion of private members of {{Closure}}. A closure class
> does not inherit them, and the metaclass of any other {{Closure}} subclass
> does not list them.
> Cause: {{ClosureMetaClass.getProperties}} returns the property list of the
> metaclass of {{Closure}} itself, which includes Closure's own private fields
> and properties. {{MethodRankHelper.getPropertySuggestionString}} ranks that
> list for the "Possible solutions" text.
> Verified on 4.0.33, 5.0.8, 6.0.0 and master.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)