Sorting streams containing nulls

Sergey Kuksenko sergey.kuksenko at oracle.com
Wed Nov 7 06:08:25 PST 2012


But it is sorted stream.
How should we compare null with other values?

On 11/07/2012 05:43 PM, Remi Forax wrote:
> On 11/07/2012 02:30 PM, Brian Goetz wrote:
>> The exact specification is not yet written, but we are not expecting stream implementations or operations to do anything special with nulls.  This means nulls may be passed to lambdas or inserted into collections that do not support them, resulting in NPE.
>
> so it's an implementation bug ?
> All Queue don't accept null so either null need to be masked/unmasked or
> the implementation has to be changed.
>
> Rémi
>
>>
>>
>>
>> On Nov 7, 2012, at 5:22 AM, Georgiy Rakov wrote:
>>
>>> Hello.
>>>
>>> When we make sorted(...).iterator() on Stream instance containing one
>>> ore more nulls we receive NPE. The example of stack trace is below:
>>>
>>>      java.lang.NullPointerException
>>>           at java.util.PriorityQueue.offer(PriorityQueue.java:320)
>>>           at java.util.PriorityQueue.add(PriorityQueue.java:306)
>>>           at java.util.streams.ops.SortedOp.iterator(SortedOp.java:105)
>>>           at java.util.streams.ops.SortedOp.wrapIterator(SortedOp.java:97)
>>>           at
>>>      java.util.streams.AbstractPipeline.iterator(AbstractPipeline.java:329)
>>>           ...
>>>
>>> Could you please tell if it is considered as expected behavior or it's
>>> going to be fixed somehow.
>>>
>>> Georgiy.
>>>
>>
>
>


-- 
Best regards,
Sergey Kuksenko


More information about the lambda-dev mailing list