Author: fanningpj
Date: Sun Sep 29 07:12:48 2024
New Revision: 1921017

URL: http://svn.apache.org/viewvc?rev=1921017&view=rev
Log:
[bug-69351] fix issues with removing items from IntList

Modified:
    poi/trunk/poi/src/main/java/org/apache/poi/util/IntList.java
    poi/trunk/poi/src/test/java/org/apache/poi/util/TestIntList.java

Modified: poi/trunk/poi/src/main/java/org/apache/poi/util/IntList.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/util/IntList.java?rev=1921017&r1=1921016&r2=1921017&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/util/IntList.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/util/IntList.java Sun Sep 29 
07:12:48 2024
@@ -18,9 +18,9 @@
 package org.apache.poi.util;
 
 /**
- * A List of int's; as full an implementation of the java.util.List
+ * A List of `int`s; as full an implementation of the java.util.List
  * interface as possible, with an eye toward minimal creation of
- * objects
+ * objects.
  *
  * the mimicry of List is as follows:
  * <ul>
@@ -40,6 +40,8 @@ package org.apache.poi.util;
  *      remove(int index)
  * <li> subList is not supported
  * </ul>
+ *
+ * This class is only meant for internal use in Apache POI.
  */
 public class IntList
 {
@@ -434,6 +436,9 @@ public class IntList
         }
         int rval = _array[ index ];
 
+        if(_limit == _array.length) {
+            growArray(_limit + 1);
+        }
         System.arraycopy(_array, index + 1, _array, index, _limit - index);
         _limit--;
         return rval;
@@ -458,6 +463,9 @@ public class IntList
             if (o == _array[ j ])
             {
                 if (j+1 < _limit) {
+                    if(_limit == _array.length) {
+                        growArray(_limit + 1);
+                    }
                     System.arraycopy(_array, j + 1, _array, j, _limit - j);
                 }
                 _limit--;

Modified: poi/trunk/poi/src/test/java/org/apache/poi/util/TestIntList.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/util/TestIntList.java?rev=1921017&r1=1921016&r2=1921017&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/util/TestIntList.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/util/TestIntList.java Sun Sep 29 
07:12:48 2024
@@ -510,4 +510,30 @@ final class TestIntList {
             assertEquals(a5[j], list.get(j));
         }
     }
+
+    @Test
+    void bug69351() {
+        final int size = 10;
+        final IntList list = new IntList(size);
+        assertEquals(0, list.size());
+        for (int i = 0; i < size; i++) {
+            list.add(i);
+        }
+        assertEquals(size, list.size());
+        assertTrue(list.removeValue(size - 2));
+        assertEquals(size - 1, list.size());
+    }
+
+    @Test
+    void testRemove69351() {
+        final int size = 10;
+        final IntList list = new IntList(size);
+        assertEquals(0, list.size());
+        for (int i = 0; i < size; i++) {
+            list.add(i);
+        }
+        assertEquals(size, list.size());
+        assertEquals(size - 2, list.remove(size - 2));
+        assertEquals(size - 1, list.size());
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to