Since 1.8, there is a ClosureWriter class, which (among other things) corrects the accessed variable field of VariableExpressions inside of closures. The method correctAccessedVariable looks at each VariableExpression and tries to map the variable name to a field name inside of a synthetic Closure class generated by the ClosureWriter. If no such variable name is found, then the accessed variable field is set to null.
This last part is incorrect. The accessed variable should not be set to null. The accessed variable may point to a field in the class declaring the closure, or it may point to a closure parameter, or a local variable, etc.
I am not sure if this has any runtime effect on Groovy code, but it does have an effect on Groovy-Eclipse. Because of this problem. Field references inside of closures cannot be resolved. This affects content assist, navigation, hovers, search, refactoring (etc).
A simple null check fixes the problem in Groovy-Eclipse. Here is the change (from 1.8-rc2):
On line 288, change:
I'll think about some good test cases for this.
|Field||Original Value||New Value|
|Fix Version/s||1.8-rc-4 [ 17245 ]|
|Status||Open [ 1 ]||Closed [ 6 ]|
|Resolution||Fixed [ 1 ]|
|Project Import||Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]|
|Workflow||jira [ 12733676 ]||Default workflow, editable Closed status [ 12745423 ]|
|Project Import||Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]|
|Workflow||jira [ 12973312 ]||Default workflow, editable Closed status [ 12979402 ]|