Skip to content

Use mutable list to collect items from Stream for reversal #3304

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

Closed
wants to merge 1 commit into from

Conversation

quaff
Copy link
Contributor

@quaff quaff commented Jun 3, 2025

There are no guarantees on the type, mutability, serializability, or thread-safety of the List returned

Collector.toList() doesn't guarantee mutability, then passing it to Collections.reverse() is not safe.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 3, 2025
>> There are no guarantees on the type, mutability, serializability, or thread-safety of the List returned

`Collector.toList()` doesn't guarantee mutability, then passing it to `Collections.reverse()` is not safe.

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 3, 2025
@mp911de mp911de self-assigned this Jun 3, 2025
@mp911de mp911de added this to the 3.3.13 (2024.0.13) milestone Jun 3, 2025
@mp911de mp911de changed the title Avoid reversing List collected by Collector.toList() to ensure safety Use mutable list to collect items from Stream for reversal Jun 3, 2025
@mp911de mp911de closed this in 115beba Jun 3, 2025
mp911de added a commit that referenced this pull request Jun 3, 2025
Add unit tests.

See #3304
mp911de pushed a commit that referenced this pull request Jun 3, 2025
>> There are no guarantees on the type, mutability, serializability, or thread-safety of the List returned

`Collector.toList()` doesn't guarantee mutability, then passing it to `Collections.reverse()` is not safe.

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
Closes #3304
mp911de added a commit that referenced this pull request Jun 3, 2025
Add unit tests.

See #3304
mp911de pushed a commit that referenced this pull request Jun 3, 2025
>> There are no guarantees on the type, mutability, serializability, or thread-safety of the List returned

`Collector.toList()` doesn't guarantee mutability, then passing it to `Collections.reverse()` is not safe.

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
Closes #3304
mp911de added a commit that referenced this pull request Jun 3, 2025
Add unit tests.

See #3304
mp911de pushed a commit that referenced this pull request Jun 3, 2025
>> There are no guarantees on the type, mutability, serializability, or thread-safety of the List returned

`Collector.toList()` doesn't guarantee mutability, then passing it to `Collections.reverse()` is not safe.

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
Closes #3304
mp911de added a commit that referenced this pull request Jun 3, 2025
Add unit tests.

See #3304
@mp911de
Copy link
Member

mp911de commented Jun 3, 2025

Thank you for your contribution. That's merged, polished, and backported now.

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

Successfully merging this pull request may close these issues.

3 participants