Hi all, I am having trouble using the PropertyUtils class in the BeanUtils package. In my classes I have a property Item defined like this:
public class Foo { private List items = new ArrayList(); public List getItems() { /* bla bla */ } public void addItem( Bar newItem ) { /* bla bla */ } // etc. /** Return an item by index */ public Bar getItem( int index ) { return items.get( index ); } /** Return an item by name */ public Bar getItem( String name ) { for ( int i=0; i<items.size(); i++ ) { Bar x = (Bar) items.get( i ); if ( x.getName().equals( name ) ) { return x; } } return null; } } So there's a property 'items' which is a collection and individual items can be retrieved using either the mapped version getItem(String) or the indexed version getItem(int). I use this class with the PropertyUtils like this (there is an existing Bar with name="helpme"): // This one runs fine: Object obj = PropertyUtils.getProperty( instanceOfFoo, "item[0]" ); // This one throws a NPE: Object obj = PropertyUtils.getProperty( instanceOfFoo, "item(helpme)" ); Digging through the PropertyUtils code I found out it relies on the getPropertyDescriptor() method for getting metadata on the specified bean (the Foo class in this case). This getProperrtyDescriptor() returns *either* a java.beans.IndexPropertyDescriptor or a org.apache.commons.beanutils.MappedPropertyDescriptor and the IndexedPropertyDescriptor takes precedence. My question is: Is this the intended behaviour? My property is both mapped and indexed, and using method overloading to support this seems to be the right way to do it. - Bart Guijt - Bart Guijt Ordina Finance BIS E: [EMAIL PROTECTED] W: www.ordina-finance.nl A: Paalbergweg 46 1105 BW Amsterdam P: Postbus 94690 1090 GR Amsterdam T: +31 20 409 6660 F: +31 20 409 6674 M: +31 6 2705 0579 -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>