1. Groovy
  2. GROOVY-4747

ClosureWriter incorrectly changes the accessedVariable field of a VariableExpression


    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8-rc-2, 1.8-rc-3
    • Fix Version/s: 1.8-rc-4
    • Component/s: class generator
    • Labels:


      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:



      if (fn != null) // only overwrite if we find something more specific

      I'll think about some good test cases for this.


        Andrew Eisenberg created issue -
        Jochen Theodorou made changes -
        Field Original Value New Value
        Fix Version/s 1.8-rc-4 [ 17245 ]
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12733676 ] Default workflow, editable Closed status [ 12745423 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12973312 ] Default workflow, editable Closed status [ 12979402 ]


          • Assignee:
            Jochen Theodorou
            Andrew Eisenberg
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: