This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Fix CopyOnWriteArrayList.java
- From: Andrew Haley <aph at redhat dot com>
- To: GCJ-patches <java-patches at gcc dot gnu dot org>, classpath at gnu dot org
- Date: Tue, 27 Apr 2010 18:26:18 +0100
- Subject: Fix CopyOnWriteArrayList.java
Obvious/trivial. remove() fails if a list is empty.
Andrew.
2010-04-27 Andrew Haley <aph@redhat.com>
* java/util/concurrent/CopyOnWriteArrayList.java: Fix for empty
list.
Index: java/util/concurrent/CopyOnWriteArrayList.java
===================================================================
--- java/util/concurrent/CopyOnWriteArrayList.java (revision 158610)
+++ java/util/concurrent/CopyOnWriteArrayList.java (working copy)
@@ -452,7 +452,12 @@
public synchronized boolean remove(Object element)
{
E[] snapshot = this.data;
- E[] newData = (E[]) new Object[snapshot.length - 1];
+ int len = snapshot.length;
+
+ if (len == 0)
+ return false;
+
+ E[] newData = (E[]) new Object[len - 1];
// search the element to remove while filling the backup array
// this way we can run this method in O(n)