[
https://issues.apache.org/jira/browse/BEANUTILS-408?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Benedikt Ritter resolved BEANUTILS-408.
---------------------------------------
Resolution: Fixed
Fixed for invokeMethod, invokeExactMethod, invokeStaticMethod and
invokeExactStaticMethod in r1449465.
> MethodUtils.invokeMethod() throws NullPointerException when args==null
> ----------------------------------------------------------------------
>
> Key: BEANUTILS-408
> URL: https://issues.apache.org/jira/browse/BEANUTILS-408
> Project: Commons BeanUtils
> Issue Type: Bug
> Components: Bean / Property Utils
> Affects Versions: 1.8.3
> Environment: Using Beanutils 1.8.3
> Reporter: Federico Carbonetti
> Fix For: 1.8.4
>
>
> When you invoke MethodUtils.invokeExactMethod(object, methodName, args) with
> args==null you get a NullPointerException:
> java.lang.NullPointerException
> at
> org.apache.commons.beanutils.MethodUtils.invokeExactMethod(MethodUtils.java:352)
> at
> org.apache.commons.beanutils.MethodUtils.invokeExactMethod(MethodUtils.java:315)
> ...
> Reason is: public static Object invokeExactMethod(Object object, String
> methodName, Object arg) gets invoked (see r. 305 below) and the null wrapped
> into an array before invoking public static Object invokeExactMethod(Object
> object, String methodName, Object[] args);
> 286 /**
> 287 * <p>Invoke a method whose parameter type matches exactly the object
> 288 * type.</p>
> 289 *
> 290 * <p> This is a convenient wrapper for
> 291 * {@link #invokeExactMethod(Object object,String methodName,Object []
> args)}.
> 292 * </p>
> 293 *
> 294 * @param object invoke method on this object
> 295 * @param methodName get method with this name
> 296 * @param arg use this argument
> 297 * @return The value returned by the invoked method
> 298 *
> 299 * @throws NoSuchMethodException if there is no such accessible method
> 300 * @throws InvocationTargetException wraps an exception thrown by the
> 301 * method invoked
> 302 * @throws IllegalAccessException if the requested method is not
> accessible
> 303 * via reflection
> 304 */
> 305 public static Object invokeExactMethod(
> 306 Object object,
> 307 String methodName,
> 308 Object arg)
> 309 throws
> 310 NoSuchMethodException,
> 311 IllegalAccessException,
> 312 InvocationTargetException {
> 313
> 314 Object[] args = {arg};
> 315 return invokeExactMethod(object, methodName, args);
> 316
> 317 }
> 318
> 319
> 320 /**
> 321 * <p>Invoke a method whose parameter types match exactly the object
> 322 * types.</p>
> 323 *
> 324 * <p> This uses reflection to invoke the method obtained from a call to
> 325 * <code>getAccessibleMethod()</code>.</p>
> 326 *
> 327 * @param object invoke method on this object
> 328 * @param methodName get method with this name
> 329 * @param args use these arguments - treat null as empty array
> 330 * @return The value returned by the invoked method
> 331 *
> 332 * @throws NoSuchMethodException if there is no such accessible method
> 333 * @throws InvocationTargetException wraps an exception thrown by the
> 334 * method invoked
> 335 * @throws IllegalAccessException if the requested method is not
> accessible
> 336 * via reflection
> 337 */
> 338 public static Object invokeExactMethod(
> 339 Object object,
> 340 String methodName,
> 341 Object[] args)
> 342 throws
> 343 NoSuchMethodException,
> 344 IllegalAccessException,
> 345 InvocationTargetException {
> 346 if (args == null) {
> 347 args = EMPTY_OBJECT_ARRAY;
> 348 }
> 349 int arguments = args.length;
> 350 Class[] parameterTypes = new Class[arguments];
> 351 for (int i = 0; i < arguments; i++) {
> 352 parameterTypes[i] = args[i].getClass();
> 353 }
> 354 return invokeExactMethod(object, methodName, args, parameterTypes);
> 355
> 356 }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira