Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Removed 1st para of applicability; it is redundant with intro

...

Code Block
bgColor#ccccff
public class Foo {
  static private final int MAX_COUNT;

  public void counter() {
    int count = 0;
    while (condition()) {
      /* ... */
      if (count++ > MAX_COUNT) return;
    }
  }

  /* No other method references count */
  /* but several other methods reference MAX_COUNT */
}

Applicability

Do not use a larger scope than necessary because it will result in less reliable code.

Detecting local variables that are declared in a larger scope than is required by the code as written is straightforward and can eliminate the possibility of false positives.

...