Fix CopyOnWriteArrayList.java

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Obvious/trivial.  remove() fails if a list is empty.

Andrew.


2010-04-27  Andrew Haley  <aph@xxxxxxxxxx>

        * 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)


[Index of Archives]     [Linux Kernel]     [Linux Cryptography]     [Fedora]     [Fedora Directory]     [Red Hat Development]

  Powered by Linux