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