A unary !, - or + is applied twice in a row and cancels out

tx0/java:doubled-unarydefaultwarningbug

What it finds

!!ready and - -n apply an operator twice, which cancels out: the value is the operand itself. Usually one operator was typed twice, or the operand was meant to change. ~~x is left alone: code compiled to JavaScript uses it to force a 32-bit integer.

From the rule's source, doubled_unary.rs.

Example from the rule's tests
class Flags {  boolean check(boolean ready, int mask, int n) {    boolean a = !!ready;tx0 reports: !!ready applies the same operator twice    int b = ~~mask;    int c = - -n;tx0 reports: - -n applies the same operator twice    int d = -(-n + 1);    return a || !ready;  }}
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:doubled-unary" = "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:doubled-unary] reason="..."

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