[concurrency-interest] LinkedBlockingQueue does not throw NullPointerException for the method call contains

Szabolcs Ferenczi szabolcs.ferenczi at gmail.com
Sun Apr 15 17:29:01 EDT 2007


On 15/04/07, Doug Lea <dl at cs.oswego.edu> wrote:
> Szabolcs Ferenczi wrote:
> >
> > It is not inserted but queried, see "q.contains(null)"
> >
> > The documentation for method "public boolean contains(Object o)" says:
> >
> > "Throws:
> > ...
> > NullPointerException - if the specified element is null and this
> > collection does not permit null elements (optional)"
> >
>
> I believe the optionality refers to throwing the exception. ...

I do not think so because the doc also explains that null can be
queried by method contains if the collection may contain nulls. On the
other hand, LinkedBlockingQueue does not permit null elements. So,
optional might refer to this situation, i.e. that the method should
throw an exception for null argument just like methods offer and put
does.

Szabolcs


More information about the Concurrency-interest mailing list