Skip to content

refactor: refactor bad smell ToArrayCallWithZeroLengthArrayArgument#102

Closed
MartinWitt wants to merge 1 commit intoapache:masterfrom
MartinWitt:laughing-train/Qodana/-1520967352
Closed

refactor: refactor bad smell ToArrayCallWithZeroLengthArrayArgument#102
MartinWitt wants to merge 1 commit intoapache:masterfrom
MartinWitt:laughing-train/Qodana/-1520967352

Conversation

@MartinWitt
Copy link
Contributor

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 (1)

- 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 <code>size</code> and <code>toArray</code>
calls. This may result in extra <code>null</code>s at the end of the array if the collection was concurrently
shrunk during the operation.</p>
See https://shipilev.net/blog/2016/arrays-wisdom-ancients/ for more details.
@garydgregory
Copy link
Member

Hello @MartinWitt
Thank you for you PR.
This PR misses 2 call sites, git master should be up to date now. Please verify and close.

@MartinWitt
Copy link
Contributor Author

This PR misses 2 call sites, git master should be up to date now.

Analyzing/fixing test classes is currently out of the scope, yes. I only fix the main source code. But the bad smell is fixed on the master. Closing it.

@MartinWitt MartinWitt closed this Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants