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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to