GROOVY-12139: vararg-of-arrays argument wrapping fails under classic …#2675
Merged
Conversation
…compilation GROOVY-11182's reproducer (a single byte[] passed to a byte[]... parameter) still failed with IllegalArgumentException when dispatched through MetaMethod#doMethodInvoke — the classic call-site path, and any other route through the reflective MOP invocation. The original fix only added a test; the invokedynamic chain's own varargs adaptation happened to handle the case, masking the gap under the default compilation mode. Root cause: ParameterTypes#fitToVargs treated any trailing array argument as the pre-packed varargs array. Being an array is not sufficient — a byte[] passed to byte[]... is a single element of the byte[][] varargs array. The argument now passes through only when it is assignable to the varargs parameter type or is an array of the same dimension (whose elements the downstream argument coercion converts, e.g. Integer[] for int...); otherwise it is wrapped as an element. Adds a classic-compilation (indy=false) variant of the GROOVY-11182 test. Also reproducible on GROOVY_5_0_X, so a candidate for backport.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2675 +/- ##
==================================================
+ Coverage 68.5934% 68.6889% +0.0955%
- Complexity 33951 34106 +155
==================================================
Files 1535 1536 +1
Lines 128543 128903 +360
Branches 23335 23363 +28
==================================================
+ Hits 88172 88542 +370
+ Misses 32555 32530 -25
- Partials 7816 7831 +15
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: 2d46893 Learn more about TestLens at testlens.app. |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes classic (non-invokedynamic) reflective MOP varargs adaptation for “vararg-of-arrays” cases, where a trailing array argument was incorrectly treated as the already-packed varargs array (e.g., byte[] passed to byte[]... should be wrapped into byte[][]).
Changes:
- Refines
ParameterTypes#fitToVargsso the last argument only passes through as the varargs array when it’s assignable to the varargs parameter type, or when it’s an array of the same dimension (allowing downstream coercion likeInteger[]→int[]). - Adds a classic-compilation (
indy=false) regression test variant for GROOVY-11182 to cover theMetaMethod#doMethodInvokepath.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/test/groovy/bugs/Groovy11182.groovy | Adds a classic-compilation regression test using GroovyShell with indy=false to exercise the reflective/MOP call-site path. |
| src/main/java/org/codehaus/groovy/reflection/ParameterTypes.java | Updates varargs argument “fit” logic to avoid misclassifying trailing arrays as the pre-packed varargs array in vararg-of-arrays scenarios. |
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.
…compilation
GROOVY-11182's reproducer (a single byte[] passed to a byte[]... parameter) still failed with IllegalArgumentException when dispatched through MetaMethod#doMethodInvoke — the classic call-site path, and any other route through the reflective MOP invocation. The original fix only added a test; the invokedynamic chain's own varargs adaptation happened to handle the case, masking the gap under the default compilation mode.
Root cause: ParameterTypes#fitToVargs treated any trailing array argument as the pre-packed varargs array. Being an array is not sufficient — a byte[] passed to byte[]... is a single element of the byte[][] varargs array. The argument now passes through only when it is assignable to the varargs parameter type or is an array of the same dimension (whose elements the downstream argument coercion converts, e.g. Integer[] for int...); otherwise it is wrapped as an element.
Adds a classic-compilation (indy=false) variant of the GROOVY-11182 test. Also reproducible on GROOVY_5_0_X, so a candidate for backport.