harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r765552 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/LinkedList.java test/api/common/org/apache/harmony/luni/tests/java/util/LinkedListTest.java
Date Thu, 16 Apr 2009 10:03:29 GMT
Author: tellison
Date: Thu Apr 16 10:03:29 2009
New Revision: 765552

URL: http://svn.apache.org/viewvc?rev=765552&view=rev
Log:
Apply modified patch for HARMONY-6145 ([classlib][luni] java.lang.LinkedList.addAll(Collection<?
extends E> collection) runs into endless loop)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/LinkedList.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/LinkedListTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/LinkedList.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/LinkedList.java?rev=765552&r1=765551&r2=765552&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/LinkedList.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/LinkedList.java Thu
Apr 16 10:03:29 2009
@@ -279,6 +279,9 @@
         if (adding == 0) {
             return false;
         }
+        Collection<? extends E> elements = (collection == this) ?
+                new ArrayList<E>(collection) : collection;
+
         Link<E> previous = voidLink;
         if (location < (size / 2)) {
             for (int i = 0; i < location; i++) {
@@ -290,7 +293,7 @@
             }
         }
         Link<E> next = previous.next;
-        for (E e : collection) {
+        for (E e : elements) {
             Link<E> newLink = new Link<E>(e, previous, null);
             previous.next = newLink;
             previous = newLink;
@@ -315,8 +318,11 @@
         if (adding == 0) {
             return false;
         }
+        Collection<? extends E> elements = (collection == this) ?
+                new ArrayList<E>(collection) : collection;
+
         Link<E> previous = voidLink.previous;
-        for (E e : collection) {
+        for (E e : elements) {
             Link<E> newLink = new Link<E>(e, previous, null);
             previous.next = newLink;
             previous = newLink;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/LinkedListTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/LinkedListTest.java?rev=765552&r1=765551&r2=765552&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/LinkedListTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/LinkedListTest.java
Thu Apr 16 10:03:29 2009
@@ -213,6 +213,22 @@
         }
 	}
 
+    public void test_addAll_Self_Ljava_util_Collection() {
+        LinkedList linkedList = new LinkedList();
+        linkedList.addLast(1);
+        assertEquals(1, linkedList.size());
+        assertTrue(linkedList.addAll(linkedList));
+        assertEquals(2, linkedList.size());
+    }
+
+    public void test_addAll_Self_ILjava_util_Collection() {
+        LinkedList linkedList = new LinkedList();
+        linkedList.addLast(1);
+        assertEquals(1, linkedList.size());
+        assertTrue(linkedList.addAll(1, linkedList));
+        assertEquals(2, linkedList.size());
+    }
+
 	/**
 	 * @tests java.util.LinkedList#addFirst(java.lang.Object)
 	 */



Mime
View raw message