Scala

Scala

Made by DeepSource

length-like property is compared against values which always evaluate to the same result SC-W1091

Bug risk
Critical

length-like properties are usually used to "count" the number of elements. For example, in the context of an array, length tells us the number of elements in the array. Comparing this property against 0 using the < or >= operators is meaningless and will always evaluate to false and true respectively. This comparison is likely a mistake and should be rewritten meaningfully.

Bad Practice

// Always true
if (arr.length >= 0) {
  // ...
}

// Always false
if (arr.length < 0) {
  // ...
}

Recommended

// Array is not empty.
// Alternately, you can use `arr.isEmpty` and `arr.nonEmpty` respectively.
if (arr.length > 0) {
  // ...
}