Skip to content

Preventing unmodifiableList from being affected by changes to the original List #34718

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

Conversation

Tussle0410
Copy link
Contributor

This PR replaces Collections.unmodifiableList() with List.copyOf().

When using Collections.unmodifiableList(), if the original list changes, it can affect the unmodifiable list, potentially causing unexpected bugs.

Using List.copyOf creates an immutable list by copying the original list, which prevents unexpected bugs and makes the code more readable, improving maintainability.

Collections.unmodifiableList(values)

I changed the code from the format above to the one below.

List.copyOf(values)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 4, 2025
@bclozel
Copy link
Member

bclozel commented Apr 4, 2025

This is also likely to make performance worse as we'll allocate list of headers for each request. Rather than discussing this solution, can describe first the problem you've encountered? Maybe you can share a minimal sample application that demonstrates this happening?

Thanks

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Apr 4, 2025
@Tussle0410
Copy link
Contributor Author

Tussle0410 commented Apr 5, 2025

This wasn't a specific problem I encountered, but since it was named ReadOnlyHttpHeaders, I determined there could be reliability issues when using unmodifiableList, which is why I created this PR.

I only considered the advantage of ensuring reliability through List.copyOf(), and I didn't consider the performance implications during the copying process.

If there's a possibility of performance issues,

I will close this PR.

Thank you for your input on this matter.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 5, 2025
@bclozel bclozel closed this Apr 5, 2025
@bclozel
Copy link
Member

bclozel commented Apr 5, 2025

Thanks for the proposal we will keep things as they are unless there is a concrete case that we can look into.

@bclozel bclozel added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Apr 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants