Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloseableIterator.stream() reports improper Spliterator size #2519

Closed
sanha opened this issue Dec 22, 2021 · 1 comment
Closed

CloseableIterator.stream() reports improper Spliterator size #2519

sanha opened this issue Dec 22, 2021 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@sanha
Copy link

sanha commented Dec 22, 2021

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
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 22, 2021
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 3, 2022
@mp911de mp911de self-assigned this Jan 3, 2022
@mp911de mp911de changed the title CloseableIterator.stream() colide with toList of Java 16 CloseableIterator.stream() reports improper Spliterator size Jan 3, 2022
@mp911de
Copy link
Member

mp911de commented Jan 3, 2022

Thanks for reporting the issue. The size value of 0 was considered as size hint and although we didn't specify the SIZED characteristic, the stream used the size hint for count, toList and other operators.

@mp911de mp911de added this to the 2.5.8 (2021.0.8) milestone Jan 3, 2022
mp911de added a commit that referenced this issue Jan 3, 2022
We now report -1 as size to avoid zero-size results for count() or toList() operators.

Closes #2519
mp911de added a commit that referenced this issue Jan 3, 2022
We now report -1 as size to avoid zero-size results for count() or toList() operators.

Closes #2519
mp911de added a commit that referenced this issue Jan 3, 2022
We now report -1 as size to avoid zero-size results for count() or toList() operators.

Closes #2519
@mp911de mp911de closed this as completed in 068c50a Jan 3, 2022
@mp911de mp911de reopened this Jan 3, 2022
mp911de added a commit that referenced this issue Jan 3, 2022
We now report -1 as size to avoid zero-size results for count() or toList() operators.

Closes #2519
mp911de added a commit that referenced this issue Jan 3, 2022
We now report -1 as size to avoid zero-size results for count() or toList() operators.

Closes #2519
mp911de added a commit that referenced this issue Jan 3, 2022
We now report -1 as size to avoid zero-size results for count() or toList() operators.

Closes #2519
@mp911de mp911de closed this as completed in 3f44d26 Jan 3, 2022
schauder pushed a commit that referenced this issue Jan 13, 2022
We now report -1 as size to avoid zero-size results for count() or toList() operators.

Closes #2519
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants