Expected ISE on forking/linking for sequential()/parallel() methods not always happen
Dmitry Bessonov
dmitry.bessonov at oracle.com
Tue Dec 25 06:28:06 PST 2012
I think here's another "implementations may..." spec casefound.
To throw "java.lang.IllegalStateException: Stream source is already
consumed" stream source should truly have been consumed as the following
doesn't throw anything:
Stream<String> stream = Arrays.asList("a", "b", "c").stream();
stream.into((Stream.Destination) s -> {});
stream.into((Stream.Destination) s -> {});
stream.into((Stream.Destination) s -> {});
-Dmitry
On 24.12.2012 0:15, Brian Goetz wrote:
> 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