hi,
this patch fixes some problems with kaffe's java.util.Vector
implementation. I found them while playing around with the Vector
examples from Java Class Libraries Second Edition Vol.1 Supplement book.
One java.util.Vector example from the book is still broken, subList. I don't
have a fix for that, since I don't understand the AbstractList implementation
well enough to come up with a solution.
Patch and change log entry are attached.
cheers,
Dali
diff -ur kaffe/libraries/javalib/java/util/Vector.java patched-kaffe/libraries/javalib/java/util/Vector.java
--- kaffe/libraries/javalib/java/util/Vector.java Mon Dec 3 13:11:41 2001
+++ patched-kaffe/libraries/javalib/java/util/Vector.java Thu Feb 28 03:05:43 2002
@@ -107,8 +107,9 @@
// required because we might have a large enough, pre-allocated, empty element
// array that doesn't give us (physical) access errors
if ( index >= elementCount )
- throw new ArrayIndexOutOfBoundsException(Integer.toString(index)
- + " >= " + elementCount);
+ throw new ArrayIndexOutOfBoundsException("Array index out of range: "
+ + Integer.toString(index));
+
return elementData[index];
}
@@ -168,7 +169,7 @@
public synchronized int indexOf(Object elem, int index) {
for (int pos = index; pos < elementCount; pos++) {
Object obj = elementData[pos];
- if (elem == obj || elem.equals(obj)) {
+ if (elem == obj || (elem != null && elem.equals(obj))) {
return (pos);
}
}
@@ -287,7 +288,13 @@
if (pos > 0) {
result.append(", ");
}
- result.append(elementData[pos].toString());
+
+ Object data = elementData[pos];
+ /* if data is null, it is represented as "null".
+ * otherwise its toString() method is called.
+ */
+ String data_as_string = (data == null) ? "null" : data.toString();
+ result.append(data_as_string);
}
result.append("]");
return (result.toString());
* libraries/javalib/java/util/Vector.java:
(elementAt) Updated exception message.
(indexOf) Fixed NullPointerException.
(toString) Fixed string conversion of nulls.