commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benedikt Ritter <>
Subject [SANDBOX][BeanUtils2] Regarding BeanAccessor.populate()
Date Sun, 05 Feb 2012 13:50:52 GMT

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 

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 
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?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message