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.