GROOVY-12276: Extend the closure cycle check to the closures a wrappe… - #2813
Open
paulk-asert wants to merge 1 commit into
Open
GROOVY-12276: Extend the closure cycle check to the closures a wrappe…#2813paulk-asert wants to merge 1 commit into
paulk-asert wants to merge 1 commit into
Conversation
…r calls Closure.checkForReferenceCycle walks owner, delegate and thisObject, which are the fields a closure dispatches through. A closure which wraps another and invokes it recurses through its own field instead, so a forged graph cycling there passed the check and then exhausted the stack on invocation. Measured before the change, building each cycle by reflection, serializing and reading it back: CurriedClosure, cycle via owner rejected, InvalidObjectException ComposedClosure, cycle via first/second accepted, then StackOverflowError TrampolineClosure, cycle via original accepted, then StackOverflowError ComposedClosure was the more surprising of the two: it already opts into the check from its readResolve, so the check ran and had nothing to say about the closure's own recursion. TrampolineClosure had no readResolve at all. Add Closure.additionalReferences for a subclass to declare the closures it calls through, and walk those as well. ComposedClosure declares first and second; TrampolineClosure declares original and gains the readResolve it was missing. Only fields a closure calls belong there, which is why the walk is not simply made reflective over every Closure-valued field: a captured closure is not a recursion edge, and treating it as one would reject graphs that invoke perfectly well. The existing ComposedClosure cycle test forges its cycle through owner and delegate, so it exercised the walk that already worked; the new tests forge through the wrapped fields, and fail without this change.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2813 +/- ##
==================================================
+ Coverage 70.1837% 70.1856% +0.0019%
- Complexity 35844 35853 +9
==================================================
Files 1562 1562
Lines 132528 132540 +12
Branches 24379 24379
==================================================
+ Hits 93013 93024 +11
- Misses 31106 31109 +3
+ Partials 8409 8407 -2
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: 99aff08 Learn more about TestLens at testlens.app. |
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.
…r calls
Closure.checkForReferenceCycle walks owner, delegate and thisObject, which are the fields a closure dispatches through. A closure which wraps another and invokes it recurses through its own field instead, so a forged graph cycling there passed the check and then exhausted the stack on invocation.
Measured before the change, building each cycle by reflection, serializing and reading it back:
CurriedClosure, cycle via owner rejected, InvalidObjectException
ComposedClosure, cycle via first/second accepted, then StackOverflowError
TrampolineClosure, cycle via original accepted, then StackOverflowError
ComposedClosure was the more surprising of the two: it already opts into the check from its readResolve, so the check ran and had nothing to say about the closure's own recursion. TrampolineClosure had no readResolve at all.
Add Closure.additionalReferences for a subclass to declare the closures it calls through, and walk those as well. ComposedClosure declares first and second; TrampolineClosure declares original and gains the readResolve it was missing.
Only fields a closure calls belong there, which is why the walk is not simply made reflective over every Closure-valued field: a captured closure is not a recursion edge, and treating it as one would reject graphs that invoke perfectly well.
The existing ComposedClosure cycle test forges its cycle through owner and delegate, so it exercised the walk that already worked; the new tests forge through the wrapped fields, and fail without this change.