Repository navigation
GROOVY-12673: report and set the delegate, resolve strategy and this object of the closure a wrapper wraps - #3194
Closed
codeconsole wants to merge 10 commits into
Closed
codeconsole wants to merge 10 commits into
codeconsole wants to merge 10 commits into
Conversation
…object of the closure a trampoline wraps
… through its getters
…wraps A memoized closure calls the closure it wraps, which kept the original owner, delegate and this object, so rehydrate had no effect on calls and a dehydrated copy could not be serialized. The copy now dehydrates or rehydrates the wrapped closure and memoizes it again with an empty cache built the same way, since cached values were computed against the old owner. Closure.memoize* pass a serializable cache factory to new Memoize overloads; the existing overloads that take a cache instance share it with the copy.
…object of the closure a memoized closure wraps
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3194 +/- ##
==================================================
+ Coverage 74.1533% 74.1622% +0.0089%
- Complexity 43751 43762 +11
==================================================
Files 1692 1692
Lines 149516 149556 +40
Branches 28366 28371 +5
==================================================
+ Hits 110871 110914 +43
+ Misses 28448 28442 -6
- Partials 10197 10200 +3
🚀 New features to boost your workflow:
|
…ializable class rather than a serializable lambda A serialized memoize() closure contained a java.lang.invoke.SerializedLambda, which serialization filters commonly reject. The dehydrate test no longer depends on which exception calling a closure with no owner throws.
# Conflicts: # src/main/java/org/codehaus/groovy/runtime/memoize/Memoize.java
…does The trampoline and memoize wrappers now forward the delegate and resolve strategy to the closure they wrap, so setting them on the wrapper changed the caller's closure. Like CurriedClosure, they now wrap a copy.
This was referenced Nov 3, 2026
🚨 All tests passed but jobs failed 🚨Failed Jobs without Test Failures❌ Build and test / lts (17, ubuntu-latest) 🏷️ Commit: 35c676f Rerun ControlsClick the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The closures returned by
trampoline(),memoize*(),curry(),>>/<<andasWritable()do not report or forward the delegation settings of the closure they wrap:Seen in 4.0.33, 5.0.8 and 6.0.0 too.
TrampolineClosurepassed the wrapped closure's delegate as itsthisObject, so itsdelegatereported the owner. It now takes the wrapped closure'sthisObjectand forwardsgetDelegate,setDelegate,getResolveStrategyandsetResolveStrategyto the wrapped closure, asComposedClosuredoes. Itsclone()copies the wrapped closure, sowith/tap, which clone and then set the delegate, leave the original trampoline unchanged. Its parameter count and types now come from the wrapped closure's getters; before, a trampolined writable or composed closure reported a singleObject[]parameter.Memoize.MemoizeFunctiongets the same forwarding,thisObjectandclone(). The copy shares the cache.CurriedClosure,ComposedClosureandClosure.WritableClosureforwardgetThisObjectto the closure they call.getOwner()of these three still returns the wrapped closure, which they call through.trampoline()and theMemoize.build*methods wrap a copy of the closure, ascurry()already does, so a delegate or resolve strategy set on the wrapper reaches the copy and never the caller's closure.One commit per wrapper.
Stacked on #3190 (GROOVY-12669, memoize rehydrate/dehydrate): this branch merges it, keeping #3190's
cacheFactoryfield and constructor parameter, makingclosurenon-final (needed byclone()here), and callingsuper(closure.getOwner(), closure.getThisObject()). Until #3190 lands, this PR's diff also shows its commits. #3195 (GROOVY-12674) and #3198 (GROOVY-12677) build on this one. With #3186 (GROOVY-12665, wrapper rehydrate/dehydrate) this merges cleanly.Compatibility
A delegate or resolve strategy set on a trampolined or memoized closure now takes effect, and
thisObjectof curried, composed, writable, trampolined and memoized closures is the wrapped closure's. A delegate set oncafterc.trampoline()orc.memoize*()no longer reaches the wrapper, which holds a copy, as withcurry().Tests
These fail without the change:
ClosureCurryTest.testThisObjectClosureComposeTest.testThisObjectClosureTest.testWritableClosureThisObject(includes a@CompileStaticcase)TrampolineTest:testDelegateAndThisObject,testSetDelegateAndResolveStrategy,testWith,testParametersOfWrappedClosureTrampolineTest.testSetDelegateAndResolveStrategyLeavesTheTrampolinedClosureAloneAbstractMemoizeTestCase:testDelegateAndThisObject,testSetDelegateAndResolveStrategy,testSetDelegateAndResolveStrategyLeavesTheMemoizedClosureAlone,testWith, run byMemoizeTest,MemoizeAtMostTest,MemoizeAtLeastTestandMemoizeBetweenTestgroovy.lang.*Closure*,groovy.*Closure*,org.codehaus.groovy.runtime.*Closure*,org.codehaus.groovy.runtime.trampoline.*,org.codehaus.groovy.runtime.memoize.*,MemoizedASTTransformationTest,gls.closures.*,groovy.transform.stc.*andorg.codehaus.groovy.classgen.asm.sc.*pass. The Checkstyle and CodeNarc gates pass.