in src/main/java/org/apache/commons/beanutils2/PropertyUtilsBean.java [1269:1325]
private Object invokeMethod(
final Method method,
final Object bean,
final Object[] values)
throws
IllegalAccessException,
InvocationTargetException {
if (bean == null) {
throw new IllegalArgumentException("No bean specified " +
"- this should have been checked before reaching this method");
}
try {
return method.invoke(bean, values);
} catch (final NullPointerException | IllegalArgumentException cause) {
// JDK 1.3 and JDK 1.4 throw NullPointerException if an argument is
// null for a primitive value (JDK 1.5+ throw IllegalArgumentException)
final StringBuilder valueString = new StringBuilder();
if (values != null) {
for (int i = 0; i < values.length; i++) {
if (i>0) {
valueString.append(", ");
}
if (values[i] == null) {
valueString.append("<null>");
} else {
valueString.append(values[i].getClass().getName());
}
}
}
final StringBuilder expectedString = new StringBuilder();
final Class<?>[] parTypes = method.getParameterTypes();
if (parTypes != null) {
for (int i = 0; i < parTypes.length; i++) {
if (i > 0) {
expectedString.append(", ");
}
expectedString.append(parTypes[i].getName());
}
}
final IllegalArgumentException e = new IllegalArgumentException(
"Cannot invoke " + method.getDeclaringClass().getName() + "."
+ method.getName() + " on bean class '" + bean.getClass() +
"' - " + cause.getMessage()
// as per https://issues.apache.org/jira/browse/BEANUTILS-224
+ " - had objects of type \"" + valueString
+ "\" but expected signature \""
+ expectedString + "\""
);
if (!BeanUtils.initCause(e, cause)) {
LOG.error("Method invocation failed", cause);
}
throw e;
}
}