[concurrency-interest] LinkedBlockingQueue does not throw NullPointerException for the method call contains
joe.bowbeer at gmail.com
Sun Apr 15 17:45:35 EDT 2007
On 4/15/07, Doug Lea <dl at cs.oswego.edu> wrote:
> I believe the optionality refers to throwing the exception. In collections
> (like Hashtable etc) where nulls cannot be handled at all (you cannot
> get the hashCode of null), methods contains, remove, and so on
> throw exceptions for null arguments. In others, they simply return
> failure indications.
> I suppose this could be made more consistent than it is, but
> given the preference some people have to allow nulls as elements
> in some kinds of collections, but to have others where they cannot
> possibly be present, you cannot make it entirely consistent.
OK - I can see this spelled out in the Collection spec:
"Attempting to query the presence of an ineligible element may throw
an exception, or it may simply return false; some implementations will
exhibit the former behavior and some will exhibit the latter. More
generally, attempting an operation on an ineligible element whose
completion would not result in the insertion of an ineligible element
into the collection may throw an exception or it may succeed, at the
option of the implementation. Such exceptions are marked as "optional"
in the specification for this interface."
More information about the Concurrency-interest