mirror of
https://github.com/corda/corda.git
synced 2025-06-17 22:58:19 +00:00
Fix an off-by-1 error in the remove method.
The change to only grow the array when the capacity has been reached exposed a bug in the remove method when shifting the array elements.
This commit is contained in:
@ -131,13 +131,14 @@ public class ArrayList<T> extends AbstractList<T> implements java.io.Serializabl
|
||||
public T remove(int index) {
|
||||
T v = get(index);
|
||||
|
||||
if (index == size - 1) {
|
||||
int newSize = size - 1;
|
||||
|
||||
if (index == newSize) {
|
||||
array[index] = null;
|
||||
} else {
|
||||
System.arraycopy(array, index + 1, array, index, size - index);
|
||||
System.arraycopy(array, index + 1, array, index, newSize - index);
|
||||
}
|
||||
|
||||
int newSize = size - 1;
|
||||
shrink(newSize);
|
||||
size = newSize;
|
||||
|
||||
|
Reference in New Issue
Block a user