Prior to Java SE 8, most implementations of Collection.removeAll(Collection) and
retainAll(Collection) return false and silently ignore a null parameter if the collection
itself was empty. In Java 8, all collection implementations throw a
NullPointerException if null is provided as a parameter.
To identify where these exceptions might occur, this rule flags the invocation of the
removeAll(Collection) and the retainAll(Collection) methods
in the following implementations and interfaces so
that you can evaluate your logic to avoid an unexpected NullPointerException.
- java.util.ArrayDeque
- java.util.ArrayList
- java.util.Collection
- java.util.Deque
- java.util.EnumSet
- java.util.LinkedList
- java.util.List
- java.util.NavigableSet
- java.util.PriorityQueue
- java.util.PriorityQueue
- java.util.Queue
- java.util.Set
- java.util.SortedSet
- java.util.Stack
- java.util.Vector
- java.util.concurrent.ArrayBlockingQueue
- java.util.concurrent.BlockingDeque
- java.util.concurrent.BlockingQueue
- java.util.concurrent.ConcurrentLinkedDeque
- java.util.concurrent.ConcurrentLinkedQueue
- java.util.concurrent.CopyOnWriteArrayList
- java.util.concurrent.CopyOnWriteArraySet
- java.util.concurrent.DelayQueue
- java.util.concurrent.LinkedBlockingDeque
- java.util.concurrent.LinkedBlockingQueue
- java.util.concurrent.LinkedTransferQueue
- java.util.concurrent.PriorityBlockingQueue
- java.util.concurrent.TransferQueue
- javax.management.AttributeList
- javax.management.relation.RoleList
- javax.management.relation.RoleList
- javax.management.relation.RoleUnresolvedList
The retainAll(Collection) method
is flagged for the following implementations. For these, the removeAll(Collection) method
already throws a NullPointerExceptions in Java 6 and Java 7.
- java.util.concurrent.ConcurrentSkipListSet
- java.util.HashSet
- java.util.LinkedHashSet
- java.util.TreeSet
- javax.print.attribute.standard.JobStateReasons
Java 8 does not introduce a behavior change for the following collection implementations,
so they are not flagged by this rule:
- java.beans.beancontext.BeanContextServicesSupport - continues to throw
UnsupportedOperationException
- java.beans.beancontext.BeanContextSupport - continues to throw
UnsupportedOperationException
- java.util.concurrent.SynchronousQueue - continues to have the Java 7 behavior and does not throw a
NullPointerException
For additional information about the java.util.Collection interface and its implementations,
see the
Interface java.util.Collection Java documentation.