First element of a parallel stream? +possible bug report
Paul Sandoz
paul.sandoz at oracle.com
Wed Dec 5 00:36:14 PST 2012
On Dec 4, 2012, at 10:43 PM, Dmitry Bessonov <dmitry.bessonov at oracle.com> wrote:
> On 05.12.2012 1:01, Paul Sandoz wrote:
>> On Dec 4, 2012, at 3:05 PM, Dmitry Bessonov <dmitry.bessonov at oracle.com> wrote:
>>
>>> 1)Question:
>>>
>>> Is the result of the following chain of operations defined
>>> and should be the same on all hardware/implementations?
>>>
>>> Arrays.asList("first", "second", "last").parallel().findFirst();
>>>
>> Yes, it will return the same result as for stream().findFirst().
>>
>>
>>> 2) Report: Slightly modified version throws NPE
>>> (with the yesterday's state of the repo) :
>>>
>>> Arrays.asList("first", "second", null, "last").parallel().findFirst();
>>>
>> Right, Optional is totally null intolerant at the moment.
>
>
> I know that it's about the parallel() implementation
> but if the result is strictly defined - always the first element
> then not tolerating the third 'null'
> really looks like a bug no matter if Optional accepts nulls or not...
>
I agree it's a bug, one that is non-deterministic. That could also happen for findAny as well. The find op is too aggressive creating Optional instances, only one optional instance should be created after the root task has completed.
Paul.
More information about the lambda-dev
mailing list