[ 
http://issues.apache.org/jira/browse/BEANUTILS-245?page=comments#action_12431011
 ] 
            
Pawan Kumar Shrivastava commented on BEANUTILS-245:
---------------------------------------------------

I think, i can see now why its not using add() method. Consider there is no 
item in the list and so if Property Utils uses add(), it will not know what 
type of Obejct is need to added in the List.

E.g. if i pass PropertyUtils.setNestedProperty(bean, "list[0].id", "1")

and if PropertyUtils uses add method then it need to invoke something like this 
- 

bean.getList().add(0, new ListElement())
bean.getList().get(0).setId("1")

But PropertyUtils can not know, what instance it has to put in the List at the 
first place.

So i think i shall be using something like - 

PropertyUtils.getNestedProperty(bean, "list")

Then chek what i get back and if its a list then check the size and if its 0 or 
equal to the index where i want to set the value, then add the item in the list 
and then invoke PropertyUtils.setNestedProperty(bean, "list[0].id", "1");

Thanks 

Pawan



> Problem setting nested index property or combined property (with index 
> property)
> --------------------------------------------------------------------------------
>
>                 Key: BEANUTILS-245
>                 URL: http://issues.apache.org/jira/browse/BEANUTILS-245
>             Project: Commons BeanUtils
>          Issue Type: Bug
>    Affects Versions: 1.7.0 Release
>         Environment: Windows XP Professional, Java 5
>            Reporter: Pawan Kumar Shrivastava
>
> This is the specific problem, when you are setting a nested index property 
> i.e.  - 
> list1[0].value
> Now i have initialized list1 as = new ArrayList(). Obviously the size is 0. 
> So PropertyUtils uses List.set(index, value) method, which throws 
> IndexOutOfBoundsException as the size and index are same.
> I think it should check the index and size first and then decide whether to 
> call add(index, value) or set(index, value).
> Please let me know, if my understanding is wrong. One potential misuse i can 
> see is what if someone passes index 100. But not sure if this can be resolved 
> by somehow shrinking the list.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to