Description
Stream.toList()
was added in Java 16.
In here, Nodes.builder(…)
decides to generate a fixed size node or a variable size node.
The result of AbstractPipeline.exactOutputSizeIfKnown()
is used as the size, and the method checks the characteristics
flags of a source spliterator.
The default implementation of CloseableIterator.stream()
in Spring data seems to create a source spliterator with characteristic
representing fixed size of 0.
Because of this, Nodes.builder(...)
generates a fixed size node builder with size 0.
After, when Stream.toList()
try to put an element to this node builder, it throws an exception in FixedNodeBuilder.accept(T)
with message
Accept exceeded fixed size of 0
.
You can reproduce this issue using the code below.
val springIterator = object : CloseableIterator<Int>, Iterator<Int> by (0..10).iterator() {
override fun remove() = Unit
override fun close() = Unit
}
val list = springIterator.stream().toList()
It would be nice to resolve this collision.
Tested with
- Zulu JDK 17.0.1
- Spring data commons 2.6.0