AmarGhugare opened a new pull request, #1891:
URL: https://github.com/apache/commons-lang/pull/1891

   `MethodUtils` and `ConstructorUtils` handle some varargs calls differently 
from Java:
   
   - An array assignable to the varargs array type is not used as the varargs 
array unless its class is exactly that type. `invokeMethod(target, "objects", 
(Object) new String[] {"a", "b"})` on `objects(Object... values)` receives one 
element instead of two, and the same call on `sequences(CharSequence... 
values)` throws `NoSuchMethodException`. `invokeConstructor` behaves the same 
way as `invokeMethod`. In Java, `target.objects(new String[] {"a", "b"})` 
receives two elements.
   - A `null` element for a boxed varargs type throws. `invokeMethod(target, 
"integers", 1, null)` on `integers(Integer... values)` throws 
`IllegalArgumentException` caused by a `NullPointerException` while unboxing. 
Java passes `[1, null]`.
   
   Changes:
   
   - `toVarArgs` now treats the last argument as the varargs array when it is 
an instance of the varargs array type, not only when its class is equal to it.
   - `getMatchingAccessibleMethod` no longer compares such an array against the 
element type when it checks varargs arguments.
   - `toVarArgs` leaves a `null` element as `null` when the component type is 
not primitive.
   
   Behavior that stays the same: an array that is not assignable to the varargs 
array type, such as `int[]` for `Object...`, is still a single element; 
individual elements still work; and a `null` element for a primitive varargs 
type is still rejected with `NoSuchMethodException`.
   
   Compatibility: a caller that passes a `String[]` to an `Object...` method 
and relies on it arriving as a single element will now get its elements, as 
with a Java call.
   
   Tests: `MethodUtilsTest` and `ConstructorUtilsTest` cover array and element 
calls, a static method, a `CharSequence...` method, a `null` boxed element, and 
the primitive guards. The new array and null-element tests fail on current 
master and pass with this change.
   
   Validation: the default `mvn` build passed with 118,213 tests, 0 failures, 
and 29 skipped. That build includes RAT, Javadoc, JaCoCo, Checkstyle, japicmp, 
SpotBugs, and PMD.


-- 
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