Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6570575

Cannot remove elements from CopyOnWriteArrayList subLists

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 7
    • 7
    • core-libs
    • None

      This program:

      public class Bug34 {
          public static void main(String[] args) throws Throwable {
      java.util.List x
      = new java.util.concurrent.CopyOnWriteArrayList().subList(0,0);
      x.add("foo");
      x.remove("foo");
      assert(x.isEmpty());
          }
      }

      throws

      Exception in thread "main" java.lang.UnsupportedOperationException
      at java.util.concurrent.CopyOnWriteArrayList$COWSubListIterator.remove(CopyOnWriteArrayList.java:1297)
      at java.util.AbstractCollection.remove(AbstractCollection.java:270)
      at Bug34.main(Bug34.java:6)

      which violates the invariant that if add(x) succeeds, then remove(x) should as well.
      Also, that if remove(int) is supported, then remove(Object) should also be.

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: