Hi,
I'm working on populate and tried to stick to the convention of throwing
exceptions for illegal inputs:
* passing null will cause NullPointerException
* passing an empty Map will have no effect
* passing a Map with null keys will cause NullPointerException
* passing a Map with null values will set those properties to null
* passing a Map with null values for primitive properties will cause a
IllegalArgumentException
But this is in contrast to BeanUtils1. Looking at the implementation of
BeanUtilsBean.populate() I can see that:
* passing null does nothing
* passing an empty map does nothing
* Null keys will be ignored
Now I think, that throwing exceptions is better than just accepting
every value. Am I right with that?
Also, I'm wondering how populate should behave if a value for a read
only property is passed. Looking at BeanUtils1 I've seen that
BeanUtilsBean.populate() just ignores those properties (line 974 in
BeanUtilsBean).
Currently I've a pretty straight forward implementation:
public void populate( Map<String, Object> properties ) throws
IllegalAccessException, IllegalArgumentException,
InvocationTargetException, NoSuchMethodException, IntrospectionException
{
checkNotNull( properties, "Can not populate null!" );
for ( String propertyName : properties.keySet() )
{
checkNotNull( propertyName, "Null is not an allowed property
key!" );
setProperty( propertyName ).withValue( properties.get(
propertyName ) );
}
}
Calling setProperty will result in a NoSuchMethodException been thrown,
if there is no setter method for a given key. I thing that is convenient
looking at the overall design of BeanUtils2.
To sum this all up: How should populate() behave, if the property for a
given key is read only?
Regards,
Benedikt
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org