Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.6.3, 1.6.4, 1.7-beta-1, 1.6.5, 1.7-beta-2
-
Component/s: groovy-jdk
-
Labels:None
-
Testcase included:yes
-
Patch Submitted:Yes
-
Number of attachments :
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()
}
The closure is now cloned during the super() call, so owner and delegate will always be different from the original closure.