Behavior of concat(null)

elena votchennikova elena.votchennikova at oracle.com
Thu Nov 22 07:35:44 PST 2012


Remi, Brian,

I try to call stream.concat(null); - case (1).


Thanks,
Elena


On 20.11.2012 3:20, Brian Goetz wrote:
> Its pretty reasonable for (1) to throw NPE.
>
> On 11/19/2012 5:57 PM, Remi Forax wrote:
>> Elena,
>> just to understand do you try to call
>>      1) stream.concat(null);
>> or
>>      2) stream.concate(stream2);    // with some null in stream2
>>
>> for case 1) concat should throw a NPE, for case 2) see the answer of
>> Brian :)
>>
>> Rémi
>>
>> On 11/19/2012 04:57 PM, Brian Goetz wrote:
>>> We do not guarantee that any given operation WILL or WILL NOT throw NPE
>>> when present with nulls.  We have made some efforts to avoid throwing
>>> NPEs from within the Streams library code, but even that is not
>>> guaranteed (put that in the "reasonable efforts" category.)  We expect
>>> most, but not all, NPEs resulting from null elements to come from code
>>> outside java.util.stream, such as lambdas passed to the operation,
>>> Arrays.sort(), the constructor of Optional, etc.
>>>
>>> On 11/19/2012 10:17 AM, elena votchennikova wrote:
>>>> Hello,
>>>>
>>>> I'm trying to use method concat(Stream) of some Stream implementation
>>>> with null-argument and currently it doesn't throw NullPointerException.
>>>> Exception is thrown only when I call some method of the resulting
>>>> Stream, for example iterator().
>>>>
>>>> Could you please explain - is it an expected behavior or concat() with
>>>> null-argument should throw NPE?
>>>>
>>>>
>>>> Thanks a lot,
>>>> Elena
>>>>
>>


More information about the lambda-dev mailing list