src/share/classes/java/util/ArrayList.java

Print this page
rev 7046 : 4802647: Throw required NPEs from removeAll()/retainAll()
Reviewed-by: mduigou, chegar, dholmes
Contributed-by: Brandon Passanisi <brandon.passanisi@oracle.com>

@@ -669,10 +669,11 @@
      * (<a href="Collection.html#optional-restrictions">optional</a>),
      *         or if the specified collection is null
      * @see Collection#contains(Object)
      */
     public boolean removeAll(Collection<?> c) {
+        Objects.requireNonNull(c);
         return batchRemove(c, false);
     }
 
     /**
      * Retains only the elements in this list that are contained in the

@@ -689,10 +690,11 @@
      * (<a href="Collection.html#optional-restrictions">optional</a>),
      *         or if the specified collection is null
      * @see Collection#contains(Object)
      */
     public boolean retainAll(Collection<?> c) {
+        Objects.requireNonNull(c);
         return batchRemove(c, true);
     }
 
     private boolean batchRemove(Collection<?> c, boolean complement) {
         final Object[] elementData = this.elementData;