[kaffe] Bug Report: LinkedList.addAll

Guilhem Lavaux guilhem.lavaux@free.fr
Fri Jul 11 10:20:02 2003


--Boundary-00=_9MvD/o5qZH2JJ1A
Content-Type: Text/Plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Description: clearsigned data
Content-Disposition: inline

Hi,

On Friday 11 July 2003 10:02, Jeremy Buisson wrote:
> In kaffe-1.1.0, maybe this has already been reported:
>

It seems it is always hanging around.

> at least methods LinkedList.addAll(Collection) and
> LinkedList.addAll(int, Collection) do not comply to Sun's specifications.
>
> In the first form (without the position), the elements must be appended
> to the end of the list. They are currently inserted after the first
> element.
>
> In the second form, the elements must be inserted *before* the specified
> position, and not after like the current version does.
>
>

Thank you. Here is a quick patch fixing that if someone can commit it...

Changelog:
* libraries/javalib/java/util/LinkedList.java (addAll#1, addAll#2): Changed=
=20
the behaviour of addAll to comply with Sun's spec. addAll must add the=20
collection after the precised element or at the end of the list.

Guilhem.

--Boundary-00=_9MvD/o5qZH2JJ1A
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="linklist.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="linklist.patch"

Index: LinkedList.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/util/LinkedList.java,v
retrieving revision 1.5
diff -u -3 -p -r1.5 LinkedList.java
--- LinkedList.java	3 Dec 2001 03:42:07 -0000	1.5
+++ LinkedList.java	11 Jul 2003 17:18:16 -0000
@@ -139,7 +139,7 @@ public class LinkedList extends Abstract
 	}
 
 	public boolean addAll(Collection c) {
-		return addAll(0, c);
+		return addAll(length, c);
 	}
 
 	public boolean addAll(int index, Collection c) {
@@ -155,8 +155,14 @@ public class LinkedList extends Abstract
 
 		// Locate "before" and "after" elements
 		Elem before, after;
-		for (before = head; index-- > 0; before = before.next);
-		after = (before == null) ? null : before.next;
+		if (index == 0) {
+	        	before = null;
+			after = tail;
+		} else {
+			index--;
+			for (before = head; index-- > 0; before = before.next);
+			after = (before == null) ? null : before.next;
+		}
 
 		// Insert clist in between before and after
 		modCount++;

--Boundary-00=_9MvD/o5qZH2JJ1A--