Added error checks.

This commit is contained in:
Pétur Ingi Egilsson 2015-03-20 21:31:49 +01:00
parent 8f96e8b592
commit bae2ba5e3e
1 changed files with 7 additions and 6 deletions

View File

@ -29,6 +29,7 @@
*/ */
package org.antlr.v4.runtime.misc; package org.antlr.v4.runtime.misc;
import java.lang.IllegalArgumentException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -57,6 +58,8 @@ public class IntegerList {
if (capacity < 0) { if (capacity < 0) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
if (capacity > MAX_ARRAY_SIZE)
throw new IllegalArgumentException();
if (capacity == 0) { if (capacity == 0) {
_data = EMPTY_DATA; _data = EMPTY_DATA;
@ -100,13 +103,9 @@ public class IntegerList {
public final void addAll(Collection<Integer> list) { public final void addAll(Collection<Integer> list) {
ensureCapacity(_size + list.size()); ensureCapacity(_size + list.size());
int current = 0;
for (int x : list) { for (int x : list) {
_data[_size + current] = x; _data[_size++] = x;
current++; }
}
_size += list.size();
} }
public final int get(int index) { public final int get(int index) {
@ -268,6 +267,8 @@ public class IntegerList {
if (fromIndex < 0 || toIndex < 0 || fromIndex > _size || toIndex > _size) { if (fromIndex < 0 || toIndex < 0 || fromIndex > _size || toIndex > _size) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
if (fromIndex > toIndex)
throw new IllegalArgumentException();
return Arrays.binarySearch(_data, fromIndex, toIndex, key); return Arrays.binarySearch(_data, fromIndex, toIndex, key);
} }