DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=37450>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=37450

           Summary: LazyList throws IndexOutOfBoundsException when trying to
                    set a value out of list bounds
           Product: Commons
           Version: 3.1
          Platform: PC
        OS/Version: Windows XP
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: Collections
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: [EMAIL PROTECTED]


This was discovered when using struts 1.2.7 with dynamic forms (Tomcat 5.0.24,
jdk 1.4.2). The reset() method in the ActionForm used LazyList.decorate(). 

        if(rooms==null) {
            rooms = new ArrayList();
            roomPrefs.add("-");
            roomPrefs = LazyList.decorate(roomPrefs, factory);
        }


However after reset() I get the error below when it tries to initialize the
ArrayList. 

IndexOutOfBoundsException -> Index: 1, Size: 1
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
        at java.util.ArrayList.RangeCheck(ArrayList.java:507)
        at java.util.ArrayList.set(ArrayList.java:340)
        at
org.apache.commons.collections.list.AbstractListDecorator.set(AbstractListDecorator.java:97)
        at
org.apache.commons.beanutils.PropertyUtilsBean.setIndexedProperty(PropertyUtilsBean.java:1417)
        at 
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1016)
        at 
org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
        at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
        at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)
        at
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:805)
        at ....


Possible Solution: For now I've created a class similar to LazyList and have
overridden the set(object, element) method and it has worked. 

    public Object set(int index, Object element) {
        int size = list.size();

        // Grow the list
        if (index >= size) {
            for (int i = size; i <= index; i++) {
                list.add(null);
            }
        }
        return list.set(index, element);
    }

I'm not sure if I'm using LazyList the right way but thought I'd bring it to
your attention.

Thanks!

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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

Reply via email to