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

AbstractCollection.addAll() doesn't throw specified Exception

XMLWordPrintable

    • beta2
    • sparc
    • solaris_2.6
    • Verified



      Name: auR10023 Date: 07/18/2001



      AbstractCollection.addAll(Collection) does not throw
      UnsupportedOperationException for empty Collection. The javadoc says:

      public boolean addAll(Collection c)
      ...

      Specified by:
                addAll in interface Collection
           Parameters:
                c - collection whose elements are to be added to this collection.
           Returns:
                true if this collection changed as a result of the call.
           Throws:
                UnsupportedOperationException - if the addAll method is not supported by
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                this collection.
           See Also:
                add(Object)
      ...

      Here is the example:

      -----t.java-----
      import java.util.*;

      public class t {
          public static void main(String[] args) {
              ArrayList arrayList = new ArrayList();
              AbstractCollectionTest abCol = new AbstractCollectionTest();
              try {
                  abCol.addAll(arrayList);
                  System.out.println("addAll(Collection) does not throw " +
                                     "UnsupportedOperationException");
              } catch(UnsupportedOperationException use) {
                  System.out.println("addAll(Collection) throws " +
                                     "UnsupportedOperationException");
              }
          }
      }

      class AbstractCollectionTest extends AbstractCollection {
          public AbstractCollectionTest() {
              super();
          }
          public Iterator iterator() {
              return new MyIterator();
          }
          public int size() {
              return 0;
          }
      }

      class MyIterator implements Iterator {
          public boolean hasNext() {
              return false;
          }
          public Object next() {
              return null;
          }
          public void remove() {
          }
      }

      ----output----

      #java -version
      java version "1.4.0-beta_refresh"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta_refresh-b70)
      Java HotSpot(TM) Client VM (build 1.4.0-beta_refresh-b70, mixed mode)

      #java t

      addAll(Collection) does not throw UnsupportedOperationException


      ======================================================================

            jjb Josh Bloch
            avusunw Avu Avu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: