Collection and array length checks must be sensibleJAVA-W1005
A comparison involving the size of a collection or an array was found, which is always guaranteed to be either true or false.
This is a generally frivolous action and may have been caused by a typo. If this was done to prevent certain code from executing or to ensure some code always executes for debugging purposes, remove it. All debugging-related code changes should be cleaned up after their purpose is served.
Consider revisiting the expression to make sure such a comparison was intended.
Bad Practice
Certain comparisons don't ever make sense when dealing with the size of a collection or an array's length.
Consider:
someArray.length < 0
The expression above always evaluates to false
since it is impossible for an array to have a negative length.
Similarly, the following comparison is functionally useless:
someCollection.size() >= 0
The usual state of affairs is that collections cannot have negative sizes. It thus makes no sense to explicitly check if the size of a collection is non-negative as has been done here.
Recommended
Do not perform comparisons that are guaranteed to result in the same value everytime.
if (coll.size() > 24) {
// ...
}
If you need to check for when a collection is empty, you can use the isEmpty()
method to do so:
if (coll.isEmpty()) {
// ...
}