Fix CopyOnWriteArrayList.java
Andrew Haley
aph@redhat.com
Tue Apr 27 17:26:00 GMT 2010
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)
More information about the Java-patches
mailing list