8173706: Is able to set a negative j.u.Vector size in JDK9 b151
Reviewed-by: martin, psandoz, smarks
This commit is contained in:
parent
c52c77ca91
commit
1f99fea68c
@ -307,8 +307,9 @@ public class Vector<E>
|
||||
if (newSize > elementData.length)
|
||||
grow(newSize);
|
||||
final Object[] es = elementData;
|
||||
for (int to = elementCount, i = elementCount = newSize; i < to; i++)
|
||||
for (int to = elementCount, i = newSize; i < to; i++)
|
||||
es[i] = null;
|
||||
elementCount = newSize;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1443,9 +1444,8 @@ public class Vector<E>
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean tryAdvance(Consumer<? super E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
int i;
|
||||
if (action == null)
|
||||
throw new NullPointerException();
|
||||
if (getFence() > (i = index)) {
|
||||
index = i + 1;
|
||||
action.accept((E)array[i]);
|
||||
@ -1458,8 +1458,7 @@ public class Vector<E>
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void forEachRemaining(Consumer<? super E> action) {
|
||||
if (action == null)
|
||||
throw new NullPointerException();
|
||||
Objects.requireNonNull(action);
|
||||
final int hi = getFence();
|
||||
final Object[] a = array;
|
||||
int i;
|
||||
|
@ -67,12 +67,18 @@ public class VectorTest extends JSR166TestCase {
|
||||
* tests for setSize()
|
||||
*/
|
||||
public void testSetSize() {
|
||||
Vector v = new Vector();
|
||||
final Vector v = new Vector();
|
||||
for (int n : new int[] { 100, 5, 50 }) {
|
||||
v.setSize(n);
|
||||
assertEquals(n, v.size());
|
||||
assertNull(v.get(0));
|
||||
assertNull(v.get(n - 1));
|
||||
assertThrows(
|
||||
ArrayIndexOutOfBoundsException.class,
|
||||
new Runnable() { public void run() { v.setSize(-1); }});
|
||||
assertEquals(n, v.size());
|
||||
assertNull(v.get(0));
|
||||
assertNull(v.get(n - 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user