Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9683

Changed behavior of delegates in 2.5.13

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.13
    • Fix Version/s: 2.5.14, 3.0.6
    • Component/s: None
    • Labels:
      None

      Description

      I've noticed difference in how maps behave when used as delegates between 2.5.12 (and earlier versions) and 2.5.13. Consider this code snippet:

      class MapAsDelegateProblem {
      
          static void main(String[] args) {
              new MapAsDelegateProblem().problematicCode()
          }
      
          def problematicCode() {
              def map = [:]
              callForAProblem(map) {
                  assert "abc" == BAR
              }
          }
      
          def <U> void callForAProblem(U target, Closure<?> closure) {
              closure.setDelegate(target)
              closure.setResolveStrategy(Closure.DELEGATE_FIRST)
              closure.call(target)
          }
      
          private static final BAR = "abc"
      } 

      In 2.5.x (up to 2.5.12) this code works just fine. Static field BAR is accessed from closure in line 10. But this breaks in 2.5.13. This affects also tests written in Spock. Utility method spock.lang.Specification::with works in the same way as callForAProblem.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                emilles Eric Milles
                Reporter:
                gkaczmarczyk Grzegorz Kaczmarczyk
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: