garydgregory commented on PR #1891:
URL: https://github.com/apache/commons-lang/pull/1891#issuecomment-7026176581

   Thank you for identifying these issues and providing regression tests. The 
reported bugs are valid. I committed an alternative implementation in commit 
bd57d068057083b0337ebd299ae4bd088eda949d, including all four tests from this 
PR, to address an additional compatibility issue.
   
   **1. Why I did not merge this implementation**
   
   The proposed array conversion changes behavior for callers supplying 
explicit argument types. For a target method `objects(Object... values)`:
   
   ```java
   String[] strings = { "a", "b" };
   
   MethodUtils.invokeMethod(receiver, "objects",
       new Object[] { strings },
       new Class<?>[] { Object.class });
   ```
   
   Previously, the target received one element containing `strings`. With this 
PR, it receives two elements. Method selection respects the supplied 
`Object.class`, but argument packing uses the runtime `String[]` class and 
treats it as the complete varargs array. This also affects static methods and 
constructors.
   
   For comparison, Java’s `objects((Object) strings)` receives one element. The 
distinction depends on the argument expression’s type, as described in [JLS 
§15.12.4.2](https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.12.4.2).
 Although reflection helpers have their own contracts, preserving the caller’s 
explicit type information matters here.
   
   The PR’s tests do not cover that case. Array passthrough also preserves 
array identity, permits modification of the caller’s array, and can expose 
`ArrayStoreException` when the target stores an incompatible value. These 
consequences needed documentation and coverage.
   
   **2. What the committed solution does differently**
   
   The committed implementation carries supplied or inferred argument types 
through the shared packing routine. Compatible arrays pass through, while an 
explicit element type such as `Object.class` keeps the array as one element. It 
also preserves the existing ability to supply a declared array signature with 
individual argument values.
   
   The implementation simplifies the shared code:
   
   - Reuses the existing executable matcher, removing the redundant 
component-only validation.
   - Allocates the declared component array directly and populates it with 
`Array.set`, preserving reference identity and null elements while supporting 
primitive unboxing and widening.
   
   All four PR tests were retained, with additional coverage for explicit 
types, null arrays versus null elements, fixed prefixes, empty and 
multidimensional arrays, identity and mutation, primitive widening, and 
instance/static/constructor invocation. Javadoc and release notes were updated 
accordingly.
   
   Validation included 633 comparisons against calls compiled by `javac`. The 
full Maven build passed on an identical isolated source snapshot: 111,679 
tests, zero failures or errors, and 29 skipped, with coverage, Javadoc, and 
static checks passing.
   
   Your reproductions and tests were useful in establishing the failures and 
validating the committed fix.
   
   Closing, you are credited in `changes.xml`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to