changeset 16620:622cc51a38ce

8173706: Is able to set a negative j.u.Vector size in JDK9 b151 Reviewed-by: martin, psandoz, smarks
author dl
date Fri, 03 Feb 2017 13:24:59 -0800
parents b48677ae75b4
children 06bdfec766f4
files src/java.base/share/classes/java/util/Vector.java test/java/util/concurrent/tck/VectorTest.java
diffstat 2 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/util/Vector.java	Fri Feb 03 08:15:55 2017 -0800
+++ b/src/java.base/share/classes/java/util/Vector.java	Fri Feb 03 13:24:59 2017 -0800
@@ -307,8 +307,9 @@
         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 @@
 
         @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 @@
 
         @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;
--- a/test/java/util/concurrent/tck/VectorTest.java	Fri Feb 03 08:15:55 2017 -0800
+++ b/test/java/util/concurrent/tck/VectorTest.java	Fri Feb 03 13:24:59 2017 -0800
@@ -67,12 +67,18 @@
      * 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));
         }
     }