Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
1.8.3
-
None
-
Using Beanutils 1.8.3
Description
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 *
.
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 =
;
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)
349 int arguments = args.length;
350 Class[] parameterTypes = new Class[arguments];
351 for (int i = 0; i < arguments; i++)
354 return invokeExactMethod(object, methodName, args, parameterTypes);
355
356 }
Attachments
Issue Links
- is cloned by
-
BEANUTILS-426 ConstructorUtils.invokeConstructor(Class klass, Object arg) throws NullPointerException when arg==null
- Resolved