RFR: 8357647 : Stream gatherers forward upstream size information to downstream

Johannes Döbler duke at openjdk.org
Fri May 23 15:56:02 UTC 2025


On Fri, 23 May 2025 15:15:30 GMT, Viktor Klang <vklang at openjdk.org> wrote:

> While it could be argued that unbounded Spliterators should not report SIZED / SUBSIZED, GatherSink should report an unknown emission size, so switching to downstream.begin(-1) rather than downstream.begin(size).
> 
> Includes a regression test which yields an OOME if this change is omitted.

src/java.base/share/classes/java/util/stream/GathererOp.java line 153:

> 151:             if (initializer != Gatherer.defaultInitializer()) // Optimization
> 152:                 state = initializer.get();
> 153:             sink.begin(-1); // GathererOp does not know the size of the output

The Integrator of the SO question which motivated this PR _does_ know the size of the output. In general would it be worth to enhance Integrator with something like `default long estimateSize(long streamEstimate) { return -1; }` to allow Integrator implementations to weigh in?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25418#discussion_r2104886743


More information about the core-libs-dev mailing list