Christian Franzen created LANG-1433:
---------------------------------------

             Summary: MethodUtils will throw a NPE if invokeMethod() is called 
for a var-args method
                 Key: LANG-1433
                 URL: https://issues.apache.org/jira/browse/LANG-1433
             Project: Commons Lang
          Issue Type: Bug
          Components: lang.reflect.*
    Affects Versions: 3.8.1
            Reporter: Christian Franzen


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
{code:java}
public class MyClass {
   public String myMethod(final String... args) {
      ...
   }

   public String myMethod(final Integer... args) {
      ...
   }
}
{code}
The following code will work:
{code:java}
MethodUtils.invokeMethod(myObject, "myMethod", "a", null, "c");
{code}
But this will throw a NPE:
{code:java}
MethodUtils.invokeMethod(myObject, "myMethod", "a", "b", null);
{code}

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
{code:java}
MethodUtils.invokeMethod(myObject, "myMethod", new Object[] {null});
{code}
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.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to