--- jsr166/src/main/java/util/Vector.java 2016/11/30 03:31:47 1.37 +++ jsr166/src/main/java/util/Vector.java 2016/12/01 00:35:21 1.38 @@ -1452,26 +1452,15 @@ public class Vector @SuppressWarnings("unchecked") public void forEachRemaining(Consumer action) { - int i, hi; // hoist accesses and checks from loop - Object[] a; if (action == null) throw new NullPointerException(); - if ((hi = fence) < 0) { - synchronized (Vector.this) { - expectedModCount = modCount; - a = array = elementData; - hi = fence = elementCount; - } - } - else - a = array; - if (a != null && (i = index) >= 0 && (index = hi) <= a.length) { - while (i < hi) - action.accept((E) a[i++]); - if (modCount == expectedModCount) - return; - } - throw new ConcurrentModificationException(); + final int hi = getFence(); + final Object[] a = array; + int i; + for (i = index, index = hi; i < hi; i++) + action.accept((E) a[i]); + if (modCount != expectedModCount) + throw new ConcurrentModificationException(); } public long estimateSize() {