Skip to content

GROOVY-11993: Support serializable method reference#2514

Merged
daniellansun merged 1 commit into
masterfrom
GROOVY-11993
May 5, 2026
Merged

GROOVY-11993: Support serializable method reference#2514
daniellansun merged 1 commit into
masterfrom
GROOVY-11993

Conversation

@daniellansun
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.altMetafactory when the target functional interface is Serializable.
  • Introduce a shared $deserializeLambda$ dispatcher mechanism (in AbstractFunctionalInterfaceWriter) 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-commenter
Copy link
Copy Markdown

codecov-commenter commented May 4, 2026

Codecov Report

❌ Patch coverage is 95.39474% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.8500%. Comparing base (19826e1) to head (4a5d293).

Files with missing lines Patch % Lines
...sc/StaticTypesMethodReferenceExpressionWriter.java 94.0476% 2 Missing and 8 partials ⚠️
...sgen/asm/sc/AbstractFunctionalInterfaceWriter.java 96.8750% 1 Missing and 2 partials ⚠️
...roovy/classgen/asm/sc/StaticTypesLambdaWriter.java 96.2963% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                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     
Files with missing lines Coverage Δ
.../sc/StaticTypesFunctionalInterfaceMetadataKey.java 100.0000% <100.0000%> (ø)
...ovy/classgen/asm/sc/StaticTypesLambdaAnalyzer.java 90.9639% <100.0000%> (-0.3656%) ⬇️
...roovy/classgen/asm/sc/StaticTypesLambdaWriter.java 93.9759% <96.2963%> (-0.4992%) ⬇️
...sgen/asm/sc/AbstractFunctionalInterfaceWriter.java 92.8571% <96.8750%> (+31.1550%) ⬆️
...sc/StaticTypesMethodReferenceExpressionWriter.java 91.5663% <94.0476%> (+3.6496%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@asf-gitbox-commits asf-gitbox-commits force-pushed the GROOVY-11993 branch 13 times, most recently from 509f633 to 2847877 Compare May 5, 2026 11:07
@testlens-app
Copy link
Copy Markdown

testlens-app Bot commented May 5, 2026

✅ All tests passed ✅

🏷️ Commit: 4a5d293
▶️ Tests: 193493 executed
⚪️ Checks: 48/48 completed


Learn more about TestLens at testlens.app.

@daniellansun daniellansun merged commit 924898f into master May 5, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants