Brian Goetz brian.goetz at
Mon Sep 24 17:10:35 PDT 2012

Your disbelief is well-founded, since that's not what is being 
suggested.  What we're suggesting is that findAny (or, more precisely, 
the Optional constructor called by findAny) could throw NPE if the 
stream contains a null, even if the stream also contains a non-null.  So 
the spec looks more like:

   @return an absent Optional if the stream is empty, or a present
   optional containing a selected element from the stream
   @throw NPE if the selected element of the stream is null

On 9/24/2012 7:21 PM, Doug Lea wrote:
> On 09/24/12 12:08, Brian Goetz wrote:
>> I think we're trying to not encourage further abuse.  There's
>> consensus that
>> present Optional should NOT store null.  Similarly, the Joe/Tim/Brian
>> cabal is
>> trying to NOT burden the streams API/implementation with any special
>> null-awareness, again for the sake of not coddling abuse.
> I'm still a little bit in disbelief about the proposal.
> The spec for findAny would look like:
>   * @return ... an absent Optional if no element matches
>   * the given predicate, or if the predicate reports true for
>   * a null argument and the stream contains a null element,
>   * possibly even if the predicate also holds for another
>   * nonnull element
> OK?
> -Doug

More information about the lambda-libs-spec-observers mailing list