gora icon indicating copy to clipboard operation
gora copied to clipboard

refactor: refactor bad smell ToArrayCallWithZeroLengthArrayArgument

Open MartinWitt opened this issue 1 year ago • 0 comments

Repairing Code Style Issues

ToArrayCallWithZeroLengthArrayArgument

The performance of the empty array version is the same, and sometimes even better, compared to the pre-sized version. Also, passing a pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray calls. This may result in extra nulls at the end of the array if the collection was concurrently shrunk during the operation.

See https://shipilev.net/blog/2016/arrays-wisdom-ancients/ for more details.

Repairing Code Style Issues

  • ToArrayCallWithZeroLengthArrayArgument (8)

MartinWitt avatar Mar 11 '23 15:03 MartinWitt