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)
|
if (newSize > elementData.length)
|
||||||
grow(newSize);
|
grow(newSize);
|
||||||
final Object[] es = elementData;
|
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;
|
es[i] = null;
|
||||||
|
elementCount = newSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1443,9 +1444,8 @@ public class Vector<E>
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public boolean tryAdvance(Consumer<? super E> action) {
|
public boolean tryAdvance(Consumer<? super E> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
int i;
|
int i;
|
||||||
if (action == null)
|
|
||||||
throw new NullPointerException();
|
|
||||||
if (getFence() > (i = index)) {
|
if (getFence() > (i = index)) {
|
||||||
index = i + 1;
|
index = i + 1;
|
||||||
action.accept((E)array[i]);
|
action.accept((E)array[i]);
|
||||||
@ -1458,8 +1458,7 @@ public class Vector<E>
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void forEachRemaining(Consumer<? super E> action) {
|
public void forEachRemaining(Consumer<? super E> action) {
|
||||||
if (action == null)
|
Objects.requireNonNull(action);
|
||||||
throw new NullPointerException();
|
|
||||||
final int hi = getFence();
|
final int hi = getFence();
|
||||||
final Object[] a = array;
|
final Object[] a = array;
|
||||||
int i;
|
int i;
|
||||||
|
@ -67,12 +67,18 @@ public class VectorTest extends JSR166TestCase {
|
|||||||
* tests for setSize()
|
* tests for setSize()
|
||||||
*/
|
*/
|
||||||
public void testSetSize() {
|
public void testSetSize() {
|
||||||
Vector v = new Vector();
|
final Vector v = new Vector();
|
||||||
for (int n : new int[] { 100, 5, 50 }) {
|
for (int n : new int[] { 100, 5, 50 }) {
|
||||||
v.setSize(n);
|
v.setSize(n);
|
||||||
assertEquals(n, v.size());
|
assertEquals(n, v.size());
|
||||||
assertNull(v.get(0));
|
assertNull(v.get(0));
|
||||||
assertNull(v.get(n - 1));
|
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