ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/CopyOnWriteArrayList.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/CopyOnWriteArrayList.java (file contents):
Revision 1.148 by jsr166, Tue Apr 3 16:32:40 2018 UTC vs.
Revision 1.149 by jsr166, Tue Apr 3 18:52:18 2018 UTC

# Line 1188 | Line 1188 | public class CopyOnWriteArrayList<E>
1188                  throw new IndexOutOfBoundsException(outOfBounds(index, size));
1189          }
1190  
1191 +        private void rangeCheckForAdd(int index) {
1192 +            // assert Thread.holdsLock(lock);
1193 +            if (index < 0 || index > size)
1194 +                throw new IndexOutOfBoundsException(outOfBounds(index, size));
1195 +        }
1196 +
1197          public Object[] toArray() {
1198              final Object[] es;
1199              final int offset;
# Line 1347 | Line 1353 | public class CopyOnWriteArrayList<E>
1353          public void add(int index, E element) {
1354              synchronized (lock) {
1355                  checkForComodification();
1356 <                if (index < 0 || index > size)
1351 <                    throw new IndexOutOfBoundsException(
1352 <                            outOfBounds(index, size));
1356 >                rangeCheckForAdd(index);
1357                  CopyOnWriteArrayList.this.add(offset + index, element);
1358                  expectedArray = getArray();
1359                  size++;
# Line 1368 | Line 1372 | public class CopyOnWriteArrayList<E>
1372  
1373          public boolean addAll(int index, Collection<? extends E> c) {
1374              synchronized (lock) {
1375 <                if (index < 0 || index > size)
1372 <                    throw new IndexOutOfBoundsException(
1373 <                            outOfBounds(index, size));
1375 >                rangeCheckForAdd(index);
1376                  final Object[] oldArray = getArrayChecked();
1377                  boolean modified =
1378                      CopyOnWriteArrayList.this.addAll(offset + index, c);
# Line 1421 | Line 1423 | public class CopyOnWriteArrayList<E>
1423          public ListIterator<E> listIterator(int index) {
1424              synchronized (lock) {
1425                  checkForComodification();
1426 <                if (index < 0 || index > size)
1425 <                    throw new IndexOutOfBoundsException
1426 <                        (outOfBounds(index, size));
1426 >                rangeCheckForAdd(index);
1427                  return new COWSubListIterator<E>(
1428                      CopyOnWriteArrayList.this, index, offset, size);
1429              }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines