spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

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

Open bazzi2548 opened this issue 1 year ago • 1 comments

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.

bazzi2548 avatar Aug 24 '24 17:08 bazzi2548

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 avatar Aug 24 '24 18:08 philwebb

Thanks @bazzi2548!

philwebb avatar Sep 02 '24 02:09 philwebb