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

Kasper Nielsen kasper at kav.dk
Sun Apr 15 17:21:49 EDT 2007


|Hi,

Throwing a NullPointerException from Collection.contains() when 
specifying null ||is optional||.
And LinkedBlockingQueue extends AbstractCollection which allows you to 
specify null as a parameter to contains.

Personally, I would prefer that the collection classes with did not 
allow inserting of null elements would throw NullPointerException for 
all methods even if it is only optionally.

- Kasper

|Szabolcs Ferenczi wrote:
> I am trying to test LinkedBlockingQueue and I cannot get the null
> pointer test for the method contains through:
>
> public class lbqTest {
>
>     LinkedBlockingQueue q;
>
>     @Before
>     public void setUp() {
>         q = new LinkedBlockingQueue(3);
>     }
>
>     @Test (expected=NullPointerException.class)
>     public void seqContainsNull() {
>         q.contains(null);
>     }
> ...
> }
>
> What I receive is this:
>
> There was 1 failure:
> 1) seqContainsNull(lbqTest.lbqTest)
> java.lang.AssertionError: Expected exception: 
> java.lang.NullPointerException
>
> I would expect a successful test according to the documentation of the 
> method.
>
> What is wrong?
>
> Best Regards,
> Szabolcs
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>   



More information about the Concurrency-interest mailing list