An arithmetic or bit operation leaves its operand unchanged, as x * 1 or x | 0

tx0/java:no-op-arithmeticstrictwarningsmell

What it finds

total * 1, count + 0, flags | 0 and bits << 0 give back their left operand unchanged. They are leftovers from an edit, or a constant that was meant to be another. Tables of constants such as 1 << 0, whose left operand is a literal too, are left alone.

Reported is * 1, / 1, + 0, - 0, | 0, ^ 0, & -1 and shifts by 0, with a numeric left operand that is not a literal.

From the rule's source, no_op_arithmetic.rs.

Example from the rule's tests
class Math2 {  static final int FLAG = 1 << 0;   int run(int total, int flags) {    int a = total * 1;tx0 reports: leaves its left operand unchanged    int b = flags | 0;tx0 reports: leaves its left operand unchanged    int c = total + 0;tx0 reports: unchanged    String d = "x" + 0;    int e = total * 2;    return a + b + c + e + d.length();  }}
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 strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:no-op-arithmetic" = "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:no-op-arithmetic] reason="..."

tx0 explain tx0/java:no-op-arithmetic shows the same in the terminal. Found a false positive? Report it.