A for loop starts its counter where its condition is already false, so its body never runs

tx0/java:loop-never-entereddefaulterrorbug

What it finds

for (int i = 10; i < 5; i++) never runs its body: the counter starts where the condition is already false. Usually the bounds or the comparison were swapped.

Reported is a for loop that declares one counter with an integer literal and whose condition compares that counter with an integer literal, when the comparison is false for the starting value.

From the rule's source, loop_never_entered.rs.

Example from the rule's tests
class Steps {  void run(int n) {    for (int i = 10; i < 5; i++) {tx0 reports: i < 5 is false for the starting value      System.out.println(i);    }    for (int i = 0; 3 < i; i++) {tx0 reports: 3 < i is false      System.out.println(i);    }    for (int i = 10; i > 0; i--) {      System.out.println(i);    }    for (int i = 0; i < n; i++) {      System.out.println(i);    }  }}
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 in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/java:loop-never-entered" = "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:loop-never-entered] reason="..."

tx0 explain tx0/java:loop-never-entered shows the same in the terminal. Found a false positive? Report it.