Sorting streams containing nulls

Paul Sandoz paul.sandoz at oracle.com
Thu Nov 8 00:41:44 PST 2012


Hi Georgiy,

You may also run into issue with uniqueElements and groupBy.

For parallel evaluation of both cases when encounter order does not need to be preserved a ConcurrentHashMap is used.

For uniqueElements: 

- when the upstream is already sorted a different algorithm is used that currently uses null as a sentinel for the last seen value (which could be easily fixed)

- when pulling (using Iterator) a null as a sentinel for the cached value is used.

So expect more NPEs :-)

This also raises the point that it is important to test various combinations of operations for sequential push/pull and parallel because depending on how the stream is accessed and the state of the upstream the current stream may employ a different algorithm.

Paul.


On Nov 7, 2012, at 11:22 AM, Georgiy Rakov <georgiy.rakov at oracle.com> 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.
> 



More information about the lambda-dev mailing list