[b84 regression?] stream.parallel()/sequential() return the stream itself when they are not expected to

Dmitry Bessonov dmitry.bessonov at oracle.com
Fri Apr 5 08:40:49 PDT 2013


Consider the following code sample:

   Stream<String> stream = Arrays.asList("a", "b", "c").stream();
   out.println("stream = " + stream);
   out.println("stream.isParallel() = " + stream.isParallel());
   out.println("stream.parallel() = " + stream.parallel());
   out.println("stream.parallel() = " + stream.parallel());
   out.println("stream.parallel().isParallel() = " + 
stream.parallel().isParallel());


With b83 a
"java.lang.IllegalStateException: Stream is already linked to a child 
stream"
is thrown on attempt to double link a stream.


With b84 the output is quite unexpected:

stream = java.util.stream.ReferencePipeline$Head at 1f3c5b5
stream.isParallel() = false
stream.parallel() = java.util.stream.ReferencePipeline$Head at 1f3c5b5
stream.parallel() = java.util.stream.ReferencePipeline$Head at 1f3c5b5
stream.parallel().isParallel() = true


If it's not a regression
then it looks like the spec
for java.util.stream.BaseStream.parallel() deserves to be updated.


The same issue takes place with parallel->sequential
stream transformation so the spec for sequential() needs an update too.

-Dmitry




More information about the lambda-dev mailing list