Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
3.8.1
-
None
Description
Whenever calling a var-args method using invokeMethod() of MethodUtils it will throw a NPE if the last parameter value is null.
Example: Given is the following class with var-args method
public class MyClass { public String myMethod(final String... args) { ... } public String myMethod(final Integer... args) { ... } }
The following code will work:
MethodUtils.invokeMethod(myObject, "myMethod", "a", null, "c");
But this will throw a NPE:
MethodUtils.invokeMethod(myObject, "myMethod", "a", "b", null);
Further more it is not deterministic which method of the two will be called if the method search of invokeMethod() can not find a single unique match. So the code
MethodUtils.invokeMethod(myObject, "myMethod", new Object[] {null});
might call any of the two methods of MyClass and it might change with each and every invocation. The search is not deterministic due to Class.getMethods () is not deterministic.
I would categorize such a method call as a bug, due to it should not be the intention of the developer to just pick any of the methods. However, debugging such an issue is really hard if the "right" method is called "sometimes" and it can be solved by just doing a sort, which should be no big deal I belive.
Attachments
Issue Links
- links to