Expected ISE on forking/linking for sequential()/parallel() methods not always happen
Brian Goetz
brian.goetz at oracle.com
Sun Dec 23 12:15:09 PST 2012
For the implementation, .sequential() on an already-sequential stream
and .parallel() on an already-parallel stream is a no-op ("return this").
This is something to call out in the spec: "implementations may..."
Thanks,
-Brian
On 12/23/2012 2:11 PM, Dmitry Bessonov wrote:
> Hello,
>
> Expected IllegalStateExceptions is not always thrown when stream (looks
> like) has been already linked to a child stream.
>
> The problem occurs with sequential()/parallel() methods when source is
> of the same type:
>
> Stream s = Arrays.asList(1, 2, 3).parallelStream();
> Stream p1 = s.parallel();
> Stream p2 = s.parallel();
> Stream s1 = s.sequential();
>
> No ISEs thrown. Just as nothing happens in the case of sequential stream:
>
> Stream s = Arrays.asList(1, 2, 3).stream();
> Stream f1 = s.filter( e -> true );
> Stream s1 = s.sequential();
> Stream s2 = s.sequential();
> Stream s3 = s.sequential();
>
> s, s1, s2, s3 refer to the same instance.
> The spec for sequential() gives some slight hint on this.
> Method parallel() has no spec (in b69) at all.
>
> I might assume that the verdict - if it's a bug or not depends on how
> exactly possibly thrown
> "java.lang.IllegalStateException: Stream is already linked to a child
> stream"
> is going to be specified.
>
> -Dmitry
>
More information about the lambda-dev
mailing list