-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8u25
-
x86_64
-
windows_7
FULL PRODUCT VERSION :
Oracle Corporation 1.7.0_65 - OS : Windows 7, x86
ADDITIONAL OS VERSION INFORMATION :
Windows 7 x86 - updated with Windows update
A DESCRIPTION OF THE PROBLEM :
Using the constructor with initialCapacity, then use set() will throw an Exception although the array is created, but size isn't set correctly.
Using ensureCapacity() won't work neither because it is based on the elementData array instead of size.
There are other side effects because of the static DEFAULT_CAPACITY with ensureCapacity().
The only way to make this work is to use add() as many time as required after using the constructor.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
List test = new ArrayList(10);
test.set(5, "test");
note that - test.size() = 0 instead of 10
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
test.size() returns 10
set(5, ...) works
ACTUAL -
throws an Exception IndexOutOfBoundsException
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 5, Size: 0
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
using add() as many time as initialCapacity after the constructor
Oracle Corporation 1.7.0_65 - OS : Windows 7, x86
ADDITIONAL OS VERSION INFORMATION :
Windows 7 x86 - updated with Windows update
A DESCRIPTION OF THE PROBLEM :
Using the constructor with initialCapacity, then use set() will throw an Exception although the array is created, but size isn't set correctly.
Using ensureCapacity() won't work neither because it is based on the elementData array instead of size.
There are other side effects because of the static DEFAULT_CAPACITY with ensureCapacity().
The only way to make this work is to use add() as many time as required after using the constructor.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
List test = new ArrayList(10);
test.set(5, "test");
note that - test.size() = 0 instead of 10
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
test.size() returns 10
set(5, ...) works
ACTUAL -
throws an Exception IndexOutOfBoundsException
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 5, Size: 0
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
using add() as many time as initialCapacity after the constructor