in src/main/java/org/apache/commons/beanutils2/PropertyUtilsBean.java [1576:1618]
public void setSimpleProperty(final Object bean, final String name, final Object value)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
Objects.requireNonNull(bean, "bean");
Objects.requireNonNull(name, "name");
final Class<?> beanClass = bean.getClass();
// Validate the syntax of the property name
if (resolver.hasNested(name)) {
throw new IllegalArgumentException("Nested property names are not allowed: Property '" + name + "' on bean class '" + beanClass + "'");
}
if (resolver.isIndexed(name)) {
throw new IllegalArgumentException("Indexed property names are not allowed: Property '" + name + "' on bean class '" + beanClass + "'");
}
if (resolver.isMapped(name)) {
throw new IllegalArgumentException("Mapped property names are not allowed: Property '" + name + "' on bean class '" + beanClass + "'");
}
// Handle DynaBean instances specially
if (bean instanceof DynaBean) {
final DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name);
if (descriptor == null) {
throw new NoSuchMethodException("Unknown property '" + name + "' on dynaclass '" + ((DynaBean) bean).getDynaClass() + "'");
}
((DynaBean) bean).set(name, value);
return;
}
// Retrieve the property setter method for the specified property
final PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
if (descriptor == null) {
throw new NoSuchMethodException("Unknown property '" + name + "' on class '" + beanClass + "'");
}
final Method writeMethod = getWriteMethod(beanClass, descriptor);
if (writeMethod == null) {
throw new NoSuchMethodException("Property '" + name + "' has no setter method in class '" + beanClass + "'");
}
// Call the property setter method
if (LOG.isTraceEnabled()) {
final String valueClassName = value == null ? "<null>" : value.getClass().getName();
LOG.trace("setSimpleProperty: Invoking method " + writeMethod + " with value " + value + " (class " + valueClassName + ")");
}
invokeMethod(writeMethod, bean, value);
}