A block of an if, else, try, finally, synchronized or initializer is empty

tx0/java:empty-blockrecommendedwarningsmell

What it finds

An empty block after if, else, a loop, try, finally, synchronized or an initializer does nothing. Either code is missing, or the statement around it can go. A comment in the block says that it is empty on purpose.

Empty catch blocks and method bodies have rules or reasons of their own and are not reported here, nor are loops whose head does the work, as in while (it.next() != x) {}.

From the rule's source, empty_block.rs.

Example from the rule's tests
class Blocks {  static {}tx0 reports: the initializer block is empty   void run(boolean a) {    if (a) {}tx0 reports: the if block is empty    else {      stop();    }    synchronized (this) {}tx0 reports: the synchronized block is empty    if (a) {      // nothing to do yet    }    while (a) {}  }   void stop() {}}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:empty-block" = "warning"

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:empty-block] reason="..."

tx0 explain tx0/java:empty-block shows the same in the terminal. Found a false positive? Report it.