You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2024/09/29 06:06:47 UTC
[Bug 69351] New: org.apache.poi.util.IntList.removeValue(int) raises "java.lang.ArrayIndexOutOfBoundsException"
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: asdf913@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-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 69351] org.apache.poi.util.IntList.removeValue(int) raises "java.lang.ArrayIndexOutOfBoundsException"
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69351
PJ Fanning <fa...@yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
--- Comment #3 from PJ Fanning <fa...@yahoo.com> ---
Fixed using r1921017
I would still strongly recommend that users should not use IntList for their
own use cases. Find a lib that specialises in List implementations like Trove
or Guava.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 69351] org.apache.poi.util.IntList.removeValue(int) raises "java.lang.ArrayIndexOutOfBoundsException"
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69351
--- Comment #4 from asdf913@gmail.com ---
(In reply to PJ Fanning from comment #2)
> Thanks for the test case.
>
> Can I ask how you came across this issue? This is a 20 year internal POI
> class which is only used for a couple of internal POI use cases. The
> removeValue method does not even seem to be used except in tests.
>
> If you have a POI use case like reading, writing or manipulating a Microsoft
> document file, then I like to see that.
>
> If you are using IntList in a non POI use case, I would recommend that you
> switch to using a library that specialises in IntLists. I used to use Trove
> for such list implementations.
I will switch to other Java library, such as Trove which is mentioned.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 69351] org.apache.poi.util.IntList.removeValue(int) raises "java.lang.ArrayIndexOutOfBoundsException"
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69351
asdf913@gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
OS| |All
--- Comment #1 from asdf913@gmail.com ---
Test case
@Test
void testRemoveValue() throws IllegalAccessException,
NoSuchFieldException {
//
final IntList il1 = new IntList();
//
// Retrieve the "_array" field in the
"org.apache.poi.util.IntList" class
//
final int[] _array = cast(int[].class,
FieldUtils.readField(IntList.class.getDeclaredField("_array"), il1, true));
//
final int length = _array != null ? _array.length : 0;
//
// Fill the "_array" with 0,1,2,3,4.... until the
_array.length==_limit
//
IntStream.range(0, length).forEach(x -> il1.add(x));
//
// Remove the value in the "_array". The value equals to the
second last value
// in the "_array"
//
// "java.lang.ArrayIndexOutOfBoundsException" raised
//
il1.removeValue(length - 2);
//
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 69351] org.apache.poi.util.IntList.removeValue(int) raises "java.lang.ArrayIndexOutOfBoundsException"
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69351
asdf913@gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
OS|All |Windows 10
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 69351] org.apache.poi.util.IntList.removeValue(int) raises "java.lang.ArrayIndexOutOfBoundsException"
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69351
PJ Fanning <fa...@yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
OS| |All
--- Comment #2 from PJ Fanning <fa...@yahoo.com> ---
Thanks for the test case.
Can I ask how you came across this issue? This is a 20 year internal POI class
which is only used for a couple of internal POI use cases. The removeValue
method does not even seem to be used except in tests.
If you have a POI use case like reading, writing or manipulating a Microsoft
document file, then I like to see that.
If you are using IntList in a non POI use case, I would recommend that you
switch to using a library that specialises in IntLists. I used to use Trove for
such list implementations.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org