An if starts on the line where the previous if ends, which reads like a missing else
What it finds
} if (retry) { puts a new if right after the closing brace of the previous one, on the same line, where } else if (retry) { usually stands. Either the else is missing, and both branches can run, or the layout hides that the two tests are independent.
Reported is an if statement that starts on the line on which a preceding if statement ends with }.
From the rule's source, if_after_closing_brace.rs.
class Retry { void run(boolean failed, boolean retry) { if (failed) { System.out.println("failed"); } if (retry) {tx0 reports: an else may be missing System.out.println("retry"); } if (failed) { System.out.println("again"); } if (retry) { System.out.println("fine"); } }} 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:
[rules]
"tx0/java:if-after-closing-brace" = "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:if-after-closing-brace] reason="..."tx0 explain tx0/java:if-after-closing-brace shows the same in the terminal. Found a false positive? Report it.