https://bz.apache.org/bugzilla/show_bug.cgi?id=69351

            Bug ID: 69351
           Summary: org.apache.poi.util.IntList.removeValue(int) raises
                    "java.lang.ArrayIndexOutOfBoundsException"
           Product: POI
           Version: 5.3.0-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: POI Overall
          Assignee: dev@poi.apache.org
          Reporter: asdf...@gmail.com
  Target Milestone: ---

Created attachment 39880
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=39880&action=edit
Test case, workaround and suggested fix

Source code
https://github.com/apache/poi/blob/trunk/poi/src/main/java/org/apache/poi/util/IntList.java#L461

Blame

https://github.com/apache/poi/blame/a3d9bb7e3541e90340aaf6e1265767daf9b51462/poi/src/main/java/org/apache/poi/util/IntList.java#L461

Stack Trace

java.lang.ArrayIndexOutOfBoundsException
        at java.lang.System.arraycopy(Native Method)
        at org.apache.poi.util.IntList.removeValue(IntList.java:461)
        at IntListTest.testRemoveValue(IntListTest.java:30)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at java.util.ArrayList.forEach(ArrayList.java:1259)
        at java.util.ArrayList.forEach(ArrayList.java:1259)


Suggested Fix

    public boolean removeValue(final int o)
    {
        for (int j = 0; j < _limit; j++)
        {
            if (o == _array[ j ])
            {
                if (j+1 < _limit) {
                        //TODO This section is suggested fix
                        if(_limit == _array.length) {
                                //
                                        final int[] ints = new
int[_array.length + 1];
                                        //
                                        System.arraycopy(_array, 0, ints, 0,
_array.length);
                                        //
                                        _array = ints;
                                        //
                        }//if
                        //TODO This section is suggested fix
                    System.arraycopy(_array, j + 1, _array, j, _limit - j);
                }
                _limit--;
                return true;
            }
        }
        return false;
    }

Description of file within the attached Java project

IntListTest.java                      Test case
IntListWorkaround.java                Workaround
org/apache/poi/util/IntListFixed.java Suggested Fix (I just change the class
name , please just check the "removeValue(int)" method)

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to