[kaffe] Re: LinkedList.subList severely broken

Daniel Bonniot Daniel.Bonniot at inria.fr
Wed May 21 06:28:01 PDT 2003


I think I spotted the bug in the implementation of 
java.util.LinkedListIterator. It keeps a reference to the current list 
node, but in the construction, that reference is incorrect when index is 
not 0.
I attach a simple fix.

Cheers,

Daniel

-------------- next part --------------
Index: libraries/javalib/java/util/LinkedListIterator.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/util/LinkedListIterator.java,v
retrieving revision 1.1
diff -u -r1.1 LinkedListIterator.java
--- libraries/javalib/java/util/LinkedListIterator.java	14 Jul 1999 00:53:24 -0000	1.1
+++ libraries/javalib/java/util/LinkedListIterator.java	21 May 2003 13:22:52 -0000
@@ -26,6 +26,11 @@
 	LinkedListIterator(LinkedList list, int index) {
 		super(list, index);
 		elem = list.head;
+		// Position elem to the index'th element.
+		// We know that index is a valid index, because that was 
+		// checked in the constructor in AbstractListIterator.
+		for (; index > 0; index--)
+		  elem = elem.next;
 	}
 
 	public Object next() {


More information about the kaffe mailing list