Empty statements, i.e. ;
, are usually introduced by mistake, for example because:
;;
.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); }