Empty statements should be removed

  • squid : EmptyStatementUsageCheck

Empty statements, i.e. ;, are usually introduced by mistake, for example because:

  • It was meant to be replaced by an actual statement, but this was forgotten.
  • There was a typo which lead to the semicolon to be doubled, i.e. ;;.

Examples:

void doSomething() {
  ;                                                       // Non-Compliant - was used as a kind of TODO marker
}
System.out.println("Hello, world!");;                     // Non-Compliant - double ;

Rarely, they are used on purpose, as the body of a loop:

for (int i = 0; i < 3; System.out.println(i), i++);       // Non-Compliant

It is a bad practice to have side-effects outside of the loop body, and therefore that code should be refactored into:

for (int i = 0; i < 3; i ++) {                            // Compliant
  System.out.println(i);
}
Close