--- jsr166/src/jsr166e/extra/ReadMostlyVector.java 2011/12/31 05:38:24 1.17 +++ jsr166/src/jsr166e/extra/ReadMostlyVector.java 2011/12/31 06:21:46 1.19 @@ -648,16 +648,12 @@ public class ReadMostlyVector long seq = lock.awaitAvailability(); int n = count; Object[] items = array; - if (n > items.length) - continue; - boolean outOfBounds = (index < 0 || index >= n); @SuppressWarnings("unchecked") - E e = outOfBounds ? null : (E) items[index]; + E e = (index < items.length) ? (E) items[index] : null; if (lock.getSequence() == seq) { - if (outOfBounds) + if (index >= n) throw new ArrayIndexOutOfBoundsException(index); - else - return e; + return e; } } } @@ -874,18 +870,13 @@ public class ReadMostlyVector for (;;) { long seq = lock.awaitAvailability(); Object[] items = array; - int len = items.length; int n = count; - if (n > len) - continue; - boolean empty = (n == 0); @SuppressWarnings("unchecked") - E e = empty ? null : (E) items[0]; + E e = (items.length > 0) ? (E) items[0] : null; if (lock.getSequence() == seq) { - if (empty) + if (n <= 0) throw new NoSuchElementException(); - else - return e; + return e; } } } @@ -896,18 +887,13 @@ public class ReadMostlyVector for (;;) { long seq = lock.awaitAvailability(); Object[] items = array; - int len = items.length; int n = count; - if (n > len) - continue; - boolean empty = (n == 0); @SuppressWarnings("unchecked") - E e = empty ? null : (E) items[n - 1]; + E e = (n > 0 && items.length >= n) ? (E) items[n - 1] : null; if (lock.getSequence() == seq) { - if (empty) + if (n <= 0) throw new NoSuchElementException(); - else - return e; + return e; } } }