You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Benedikt Ritter <be...@systemoutprintln.de> on 2012/02/20 18:37:32 UTC
[SANDBOX][BeanUtils2] Some thoughts on indexed properties
Hi,
today I got the time to write some more code for BeanUtils2, so I
started to implement setIndexed().
Now, that I'm nearly done with it, there are two things that I'm unsure
how to handle.
1. out of bounds indices: If the user passes in an index that is out of
bounds, he will see a InvocationTargetException, that wraps an
ArrayOutOfBoundsException (if the indexed property is backed up by an
array). Can we live with that or should we implement some logic, that
checks if the index is available and if not throws the appropriate
exception? (this would also have to be applied to getIndexed)
2. wrong property names: If the user passes a property name, that
doesn't specify a property on the given bean, he will see a
NullPointerException. This is, because we do at first try to retrieve a
property descriptor from PropertyDescriptor registry and then just do a
checkNotNull with it.
I thing it would be more appropriate to throw a NoSuchMethodException,
if a string was passed in, that does not correspond to any of the
properties (to differentiate this case from a null argument been passed).
If you agree the implementation of set(String), get(String)
getIndexed(String) will have to change as well.
Regards,
Benedikt
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [SANDBOX][BeanUtils2] Some thoughts on indexed properties
Posted by Simone Tripodi <si...@apache.org>.
Hi,
> today I got the time to write some more code for BeanUtils2, so I started to
> implement setIndexed().
nice, it is missing indeed.
> 1. out of bounds indices: If the user passes in an index that is out of
> bounds, he will see a InvocationTargetException, that wraps an
> ArrayOutOfBoundsException (if the indexed property is backed up by an
> array). Can we live with that or should we implement some logic, that checks
> if the index is available and if not throws the appropriate exception? (this
> would also have to be applied to getIndexed)
to perform that check, you should get the original property, that non
necessarily could/has to be exposed in real use cases, and then verify
the index is available.
Refer how the original BeanUtils handles that, that is something users
are already used to.
> 2. wrong property names: If the user passes a property name, that doesn't
> specify a property on the given bean, he will see a NullPointerException.
> This is, because we do at first try to retrieve a property descriptor from
> PropertyDescriptor registry and then just do a checkNotNull with it.
> I thing it would be more appropriate to throw a NoSuchMethodException, if a
> string was passed in, that does not correspond to any of the properties (to
> differentiate this case from a null argument been passed).
> If you agree the implementation of set(String), get(String)
> getIndexed(String) will have to change as well.
go for NoSuchMethodException - but please don't mix stuff, please
provide separated patches - maybe the NoSuchMethodException first,
then setIndexedProperty() implementation.
TIA,
-Simo
http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org