--- old/src/share/classes/java/util/Vector.java 2014-04-15 14:08:04.913035268 -0700 +++ new/src/share/classes/java/util/Vector.java 2014-04-15 14:08:04.737035260 -0700 @@ -553,7 +553,6 @@ * ({@code index < 0 || index >= size()}) */ public synchronized void removeElementAt(int index) { - modCount++; if (index >= elementCount) { throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount); @@ -565,6 +564,7 @@ if (j > 0) { System.arraycopy(elementData, index + 1, elementData, index, j); } + modCount++; elementCount--; elementData[elementCount] = null; /* to let gc do its work */ } @@ -593,7 +593,6 @@ * ({@code index < 0 || index > size()}) */ public synchronized void insertElementAt(E obj, int index) { - modCount++; if (index > elementCount) { throw new ArrayIndexOutOfBoundsException(index + " > " + elementCount); @@ -601,6 +600,7 @@ ensureCapacityHelper(elementCount + 1); System.arraycopy(elementData, index, elementData, index + 1, elementCount - index); elementData[index] = obj; + modCount++; elementCount++; } @@ -616,8 +616,8 @@ * @param obj the component to be added */ public synchronized void addElement(E obj) { - modCount++; ensureCapacityHelper(elementCount + 1); + modCount++; elementData[elementCount++] = obj; } @@ -653,11 +653,11 @@ * method (which is part of the {@link List} interface). */ public synchronized void removeAllElements() { - modCount++; // Let gc do its work for (int i = 0; i < elementCount; i++) elementData[i] = null; + modCount++; elementCount = 0; } @@ -778,8 +778,8 @@ * @since 1.2 */ public synchronized boolean add(E e) { - modCount++; ensureCapacityHelper(elementCount + 1); + modCount++; elementData[elementCount++] = e; return true; } @@ -879,13 +879,15 @@ * @throws NullPointerException if the specified collection is null * @since 1.2 */ - public synchronized boolean addAll(Collection c) { - modCount++; + public boolean addAll(Collection c) { Object[] a = c.toArray(); int numNew = a.length; - ensureCapacityHelper(elementCount + numNew); - System.arraycopy(a, 0, elementData, elementCount, numNew); - elementCount += numNew; + synchronized (this) { + ensureCapacityHelper(elementCount + numNew); + System.arraycopy(a, 0, elementData, elementCount, numNew); + modCount++; + elementCount += numNew; + } return numNew != 0; } @@ -950,22 +952,24 @@ * @throws NullPointerException if the specified collection is null * @since 1.2 */ - public synchronized boolean addAll(int index, Collection c) { - modCount++; + public boolean addAll(int index, Collection c) { if (index < 0 || index > elementCount) throw new ArrayIndexOutOfBoundsException(index); Object[] a = c.toArray(); int numNew = a.length; - ensureCapacityHelper(elementCount + numNew); + synchronized(this) { + ensureCapacityHelper(elementCount + numNew); - int numMoved = elementCount - index; - if (numMoved > 0) - System.arraycopy(elementData, index, elementData, index + numNew, - numMoved); - - System.arraycopy(a, 0, elementData, index, numNew); - elementCount += numNew; + int numMoved = elementCount - index; + if (numMoved > 0) + System.arraycopy(elementData, index, elementData, index + numNew, + numMoved); + + System.arraycopy(a, 0, elementData, index, numNew); + modCount++; + elementCount += numNew; + } return numNew != 0; } @@ -1047,12 +1051,12 @@ * (If {@code toIndex==fromIndex}, this operation has no effect.) */ protected synchronized void removeRange(int fromIndex, int toIndex) { - modCount++; int numMoved = elementCount - toIndex; System.arraycopy(elementData, toIndex, elementData, fromIndex, numMoved); // Let gc do its work + modCount++; int newElementCount = elementCount - (toIndex-fromIndex); while (elementCount != newElementCount) elementData[--elementCount] = null;