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

Brian Goetz brian.goetz at oracle.com
Fri Apr 5 08:46:25 PDT 2013


Here is what the spec currently says:

     /**
      * Produces an equivalent stream that is parallel.
      * If this stream is already parallel, may return itself.
      *
      * <p>This is an <a 
href="package-summary.html#StreamOps">intermediate operation</a>.
      *
      * @return a parallel stream
      */

I believe this is what you are asking for?  Sequential now says the same 
thing (as will unordered() in a few minutes.)

On 4/5/2013 11:40 AM, Dmitry Bessonov wrote:
> 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