The body of an if, else or loop is a lone ; right after its head
What it finds
if (ready); and while (queue.isEmpty()); end in a semicolon, which is an empty statement and the whole body: the block on the next line runs unconditionally, or once after the loop. The semicolon is almost always a slip.
Reported are if, else, for and while bodies that are a lone ; on the same line as the statement's head. A ; on a line of its own, and a while or for loop whose head calls, assigns or increments, are left alone: such loops are often written with an empty body on purpose, as is a ; followed by a comment on the same line.
From the rule's source, stray_semicolon_body.rs.
class Loops { void run(boolean ready, java.util.Queue<String> queue) { if (ready); queue.clear();tx0 reports: this ; is the whole body of the if { queue.clear(); } while (queue.poll() != null); if (ready) ; // nothing to do while (ready); ready = false;tx0 reports: this ; is the whole body of the while for (int i = 0; i < 3; i++) ; }} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/java:stray-semicolon-body" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:stray-semicolon-body] reason="..."tx0 explain tx0/java:stray-semicolon-body shows the same in the terminal. Found a false positive? Report it.