in src/main/java/org/apache/commons/beanutils2/PropertyUtilsBean.java [1342:1403]
public boolean isReadable(Object bean, String name) {
// Validate method parameters
if (bean == null) {
throw new IllegalArgumentException("No bean specified");
}
if (name == null) {
throw new IllegalArgumentException("No name specified for bean class '" +
bean.getClass() + "'");
}
// Resolve nested references
while (resolver.hasNested(name)) {
final String next = resolver.next(name);
Object nestedBean = null;
try {
nestedBean = getProperty(bean, next);
} catch (final IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
return false;
}
if (nestedBean == null) {
throw new NestedNullException
("Null property value for '" + next +
"' on bean class '" + bean.getClass() + "'");
}
bean = nestedBean;
name = resolver.remove(name);
}
// Remove any subscript from the final name value
name = resolver.getProperty(name);
// Treat WrapDynaBean as special case - may be a write-only property
// (see Jira issue# BEANUTILS-61)
if (bean instanceof WrapDynaBean) {
bean = ((WrapDynaBean)bean).getInstance();
}
// Return the requested result
if (bean instanceof DynaBean) {
// All DynaBean properties are readable
return ((DynaBean) bean).getDynaClass().getDynaProperty(name) != null;
}
try {
final PropertyDescriptor desc =
getPropertyDescriptor(bean, name);
if (desc != null) {
Method readMethod = getReadMethod(bean.getClass(), desc);
if (readMethod == null) {
if (desc instanceof IndexedPropertyDescriptor) {
readMethod = ((IndexedPropertyDescriptor) desc).getIndexedReadMethod();
} else if (desc instanceof MappedPropertyDescriptor) {
readMethod = ((MappedPropertyDescriptor) desc).getMappedReadMethod();
}
readMethod = MethodUtils.getAccessibleMethod(bean.getClass(), readMethod);
}
return readMethod != null;
}
return false;
} catch (final IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
return false;
}
}