This is the mail archive of the
java-patches@sources.redhat.com
mailing list for the Java project.
Patch: Vector bug fixes
- To: Java Patch List <java-patches at sourceware dot cygnus dot com>
- Subject: Patch: Vector bug fixes
- From: Tom Tromey <tromey at redhat dot com>
- Date: 01 Dec 2000 21:23:00 -0700
- Reply-To: tromey at redhat dot com
I'm checking this in.
It fixes a critical bug in Vector.insertElementAt. It also fixes a
buglet in removeRange.
2000-12-01 Tom Tromey <tromey@redhat.com>
* java/util/Vector.java (insertElementAt): Unconditionally
increment elementCount.
(removeRange): Clear unused slots in vector.
Tom
Index: java/util/Vector.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/util/Vector.java,v
retrieving revision 1.10
diff -u -r1.10 Vector.java
--- Vector.java 2000/11/27 08:30:26 1.10
+++ Vector.java 2000/12/02 04:09:24
@@ -440,8 +440,9 @@
throw new ArrayIndexOutOfBoundsException(index + " > " + elementCount);
if (elementCount == elementData.length)
- ensureCapacity(++elementCount);
- modCount++;
+ ensureCapacity(elementCount + 1);
+ ++modCount;
+ ++elementCount;
System.arraycopy(elementData, index, elementData, index + 1,
elementCount - 1 - index);
elementData[index] = obj;
@@ -755,7 +756,11 @@
{
System.arraycopy(elementData, toIndex, elementData, fromIndex,
elementCount - toIndex);
+ // Clear unused elements so objects can be collected.
+ int save = elementCount;
elementCount -= (toIndex - fromIndex);
+ for (int i = elementCount; i < save; ++i)
+ elementData[i] = null;
}
}
}