1. opensymphony
  2. xwork

Commits

unkyaku  committed 79aa40f

Have set() work like get() so that we don't get IndexOutOfBoundsExceptions when trying to set indexed properties.

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@291e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits da99a0d
  • Branches master

Comments (0)

Files changed (1)

File src/java/com/opensymphony/xwork/util/XWorkList.java

View file
 
 import com.opensymphony.xwork.ObjectFactory;
 
-import java.util.AbstractList;
 import java.util.ArrayList;
 
 
 /**
- * A simple list that when requested an index that it doesn't yet hold will
- * create empty beans all the way up to and including that index using
- * ObjectFactory's {@link ObjectFactory#buildBean(java.lang.Class) buildBean} method.
+ * A simple list that guarantees that {@link #get(int)} and {@link #set(int, Object)} will always
+ * work regardless of the current size of the list.  Empty beans will be created to fill the gap
+ * between the current list size and the requested index using ObjectFactory's
+ * {@link ObjectFactory#buildBean(java.lang.Class) buildBean} method.
  *
  * @author Patrick Lightbody
  */
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
+    /**
+     * Returns the element at the specified position in this list.  An object is guaranteed to be
+     * returned since it will create empty beans to fill the gap between the current list size and
+     * the requested index.
+     *
+     * @param index index of element to return.
+     * @return the element at the specified position in this list.
+     */
     public synchronized Object get(int index) {
         while (index >= this.size()) {
             try {
 
         return super.get(index);
     }
+
+    /**
+     * Replaces the element at the specified position in this list with the specified element.
+     * This method is guaranteed to work since it will create empty beans to fill the gap between
+     * the current list size and the requested index to enable the element to be set.
+     *
+     * @param index index of element to replace.
+     * @param element element to be stored at the specified position.
+     * @return the element previously at the specified position.
+     */
+    public Object set(int index, Object element) {
+        if (index >= this.size()) {
+            get(index);
+        }
+
+        return super.set(index, element);
+    }
 }