groovy

CurriedClosure does not clone the parent closure

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.6.3, 1.6.4, 1.7-beta-1, 1.6.5, 1.7-beta-2
  • Fix Version/s: 1.6.6, 1.7-rc-1
  • Component/s: groovy-jdk
  • Labels:
    None
  • Testcase included:
    yes
  • Patch Submitted:
    Yes
  • Number of attachments :
    1

Description

Bug 3770 fixed setting delegates and resolve strategies on curried closures by passing through to the parent. As was noted in the bug comments, this creates a new issue since we are now changing the original closure which other contexts could be using at the same time. When a closure is curried the original closure should be cloned before its use as the owner.

I've attached a patch to CurriedClosure.java that clones the original closure when a CurriedClosure is created.

void testCurriedClosuresShouldNotAffectParent() {
def orig = { tmp -> println tmp }
def curriedOrig = orig.curry(1)

// This test currently fails in 1.6.5
assertNotEquals "Curried closures should not reference the original closure curried", orig, curriedOrig.getOwner()
}

Activity

Hide
blackdrag blackdrag added a comment -

The closure is now cloned during the super() call, so owner and delegate will always be different from the original closure.

Show
blackdrag blackdrag added a comment - The closure is now cloned during the super() call, so owner and delegate will always be different from the original closure.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: