Skip to content

Latest commit

 

History

History
28 lines (23 loc) · 581 Bytes

File metadata and controls

28 lines (23 loc) · 581 Bytes

Checking a provably-identical condition twice can be a sign of a logic error.

For example:

public Optional<T> first(Optional<T> a, Optional<T> b) {
  if (a.isPresent()) {
    return a;
  } else if (a.isPresent()) { // Oops--should be checking `b`.
    return b;
  } else {
    return Optional.empty();
  }
}

It can also be a sign of redundancy, which can just be removed.

public void act() {
  if (enabled) {
    frobnicate();
  } else if (!enabled) { // !enabled is guaranteed to be true here, so the check can be removed
    doSomethingElse();
  }
}