Scala

Scala

Made by DeepSource

If-else chain has a duplicate condition SC-W1086

Bug risk
Critical

One or more if statements in the if-else chain have duplicate conditions. It is likely that you meant to specify a different condition but ended up specifying a condition that is already present in the chain. Since a flawed condition can affect your application's logic, it is recommended that you address this issue.

Bad Practice

if (x % 2 == 0) {
  // ...
} else if (x % 3 == 0) {
  // ...
} else if (x % 2 == 0) { // Duplicate condition
  // ...
}

Recommended

if (x % 2 == 0) {
  // ...
} else if (x % 3 == 0) {
  // ...
} else if (x % 4 == 0) {
  // ...
}