uniqueElements().iterator() returns broken iterator

Georgiy Rakov georgiy.rakov at oracle.com
Fri Nov 30 08:28:27 PST 2012


Hello again,

when executing uniqueElements() on stream consisting of null elements 
broken iterator is returned.

Consider following code.

    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Iterator;
    import java.util.List;

    public class UniqueElementsIssue3 {
         public static void main(String arg[]) {
             Iterator<Integer> it = Arrays.asStream(new Integer[]{null,
    null, null}).uniqueElements().iterator();
             Integer i = null;
             List<Object> result1 = new ArrayList<>();
             while (it.hasNext()) {
                 i = it.next();
                 result1.add(i);
             }
             System.out.println("resul1=" +
    Arrays.toString(result1.toArray()));
         }
    }

This code throws the exception with following stacktrace.

    Exception in thread "main" java.util.NoSuchElementException
         at java.util.streams.ops.UniqOp$2.next(UniqOp.java:118)
         at UniqueElementsIssue3.main(UniqueElementsIssue3.java:19)

The reason is obvious: it.next() fails while it.hasNext() returns true.
This occurs for stream in parallel mode as well.

Could you please tell when we could expect this bug to be fixed (and 
others on uniqueElements - see two my previous letters).

Source code is attached for your convenience.

Thanks,
Georgiy,
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: UniqueElementsIssue3.java
Url: http://mail.openjdk.java.net/pipermail/lambda-dev/attachments/20121130/59e5a5f1/UniqueElementsIssue3.java 


More information about the lambda-dev mailing list