Skip to content

Use List.copyOf() instead of Collections.unmodifiableList() #42019

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

bazzi2548
Copy link
Contributor

We can safely use List.copyOf() because we check if (providers) is null.

If use List.copyOf()

  • Clean code
  • Performance optimization
  • Guarantees a truly immutable list.

We can safely use List.copyOf() because we check if (providers) is null.

If use List.copyOf()
- Clean code
- Performance optimization
- Guarantees a truly immutable list.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 24, 2024
@philwebb
Copy link
Member

I think this is probably safe, but we need to be a little careful using List.copyOf. Unlike Collections.unmodifiableList(new ArrayList<>(...)) it will throw an exception if any of the elements are null.

@philwebb philwebb added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 24, 2024
@philwebb philwebb added this to the 3.4.x milestone Aug 24, 2024
@philwebb philwebb closed this in 1ba0113 Sep 2, 2024
@philwebb philwebb modified the milestones: 3.4.x, 3.4.0-M3 Sep 2, 2024
@philwebb
Copy link
Member

philwebb commented Sep 2, 2024

Thanks @bazzi2548!

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

Successfully merging this pull request may close these issues.

3 participants