in src/main/java/org/apache/commons/beanutils2/BeanMap.java [173:213]
public Object clone() throws CloneNotSupportedException {
final BeanMap newMap = (BeanMap) super.clone();
if (bean == null) {
// no bean, just an empty bean map at the moment. return a newly
// cloned and empty bean map.
return newMap;
}
Object newBean = null;
final Class<? extends Object> beanClass = bean.getClass(); // Cannot throw Exception
try {
newBean = beanClass.newInstance();
} catch (final Exception e) {
// unable to instantiate
final CloneNotSupportedException cnse = new CloneNotSupportedException(
"Unable to instantiate the underlying bean \"" + beanClass.getName() + "\": " + e);
cnse.initCause(e);
throw cnse;
}
try {
newMap.setBean(newBean);
} catch (final Exception e) {
final CloneNotSupportedException cnse = new CloneNotSupportedException("Unable to set bean in the cloned bean map: " + e);
cnse.initCause(e);
throw cnse;
}
try {
// copy only properties that are readable and writable. If its
// not readable, we can't get the value from the old map. If
// its not writable, we can't write a value into the new map.
readMethods.keySet().forEach(key -> {
if (getWriteMethod(key) != null) {
newMap.put(key, get(key));
}
});
} catch (final Exception e) {
final CloneNotSupportedException cnse = new CloneNotSupportedException("Unable to copy bean values to cloned bean map: " + e);
cnse.initCause(e);
throw cnse;
}
return newMap;
}