GROOVY-11993: Support serializable method reference#2514
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses GROOVY-11993 by enabling Serializable support for statically-compiled method references, aligning their serialization/deserialization behavior with existing serializable lambda handling.
Changes:
- Extend static method reference bytecode generation to use
LambdaMetafactory.altMetafactorywhen the target functional interface isSerializable. - Introduce a shared
$deserializeLambda$dispatcher mechanism (inAbstractFunctionalInterfaceWriter) and register dispatcher entries for both lambdas and method references. - Add STC tests covering serializable non-capturing and capturing method references, and verifying dispatcher sharing with lambdas.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/test/groovy/groovy/transform/stc/MethodReferenceTest.groovy | Adds regression tests for serializable method reference round-trip serialization and dispatcher sharing. |
| src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java | Generates serializable method references via altMetafactory and registers method-reference deserialization helpers/dispatcher entries. |
| src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java | Refactors serializable lambda deserialization support to register dispatcher entries instead of using reflective dispatch. |
| src/main/java/org/codehaus/groovy/classgen/asm/sc/AbstractFunctionalInterfaceWriter.java | Centralizes deserialization dispatcher creation and matching logic via a SerializedLambdaKey. |
Comment on lines
+214
to
+216
| dispatcher = new BlockStatement(); | ||
| dispatcher.addStatement(returnS(callX(classX(ClassHelper.make(Objects.class)), "requireNonNull", args(nullX(), constX("Invalid lambda deserialization"))))); | ||
|
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2514 +/- ##
==================================================
+ Coverage 67.8034% 67.8500% +0.0465%
- Complexity 32266 32317 +51
==================================================
Files 1489 1490 +1
Lines 123889 124031 +142
Branches 22246 22255 +9
==================================================
+ Hits 84001 84155 +154
+ Misses 32614 32606 -8
+ Partials 7274 7270 -4
🚀 New features to boost your workflow:
|
509f633 to
2847877
Compare
2847877 to
4a5d293
Compare
✅ All tests passed ✅🏷️ Commit: 4a5d293 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.
https://issues.apache.org/jira/browse/GROOVY-11993