Expected behavior of a Streams.cycled() instance - found issues and questions
Dmitry Bessonov
dmitry.bessonov at oracle.com
Wed Oct 24 04:06:45 PDT 2012
On 23.10.2012 23:17, Paul Sandoz wrote:
> On Oct 23, 2012, at 7:11 PM, Brian Goetz <brian.goetz at Oracle.COM> wrote:
>>> 5) cycledStream.uniqueElements() leads to IllegalStateException though
>>> it should not according to common sense.
> Got a stack trace?
Sorry, my bad code minimization. This should have been:
Streams.cycle(Arrays.asList(1,2,3)).uniqueElements().into(new ArrayList<>())
And:
Exception in thread "main" java.lang.IllegalStateException: An stream of
known infinite size is input to a non-short-circuiting terminal operation
at
java.util.streams.AbstractPipeline$SequentialImplPipelineHelper.<init>(AbstractPipeline.java:192)
at
java.util.streams.AbstractPipeline.evaluateSerial(AbstractPipeline.java:129)
at
java.util.streams.AbstractPipeline.evaluate(AbstractPipeline.java:87)
at
java.util.streams.AbstractPipeline.pipeline(AbstractPipeline.java:298)
at java.util.streams.ValuePipeline.forEach(ValuePipeline.java:90)
at java.util.Collection.addAll(Collection.java:509)
at java.util.ArrayList.addAll(ArrayList.java)
at java.util.streams.ValuePipeline.into(ValuePipeline.java:115)
>
>
>> Well, I'm not sure I agree with the notion of common sense here; I think
>> its a bit much to ask the runtime to do this kind of analysis. But this
>> is a fine example of the sort of trouble we get in when we do try and
>> protect the user from themselves; this ISE is exactly what you're asking
>> for in (1), and we should probably remove it.
>>
> Yeah, we can only catch some not all cases so it is inconsistent.
Well, but it is still possible to implement a special (smart) version of
uniqueElements() for the cycled stream instances?
Dmitry
>
> However, for the above case I am wondering where the exception is thrown because it does not seem to match the places in AbstractPipeline an ISE is currently thrown.
>
> Paul.
>
>
More information about the lambda-dev
mailing list