A local variable has the name of a field of its class, which it hides

tx0/java:local-hides-fieldstrictwarningsmell

What it finds

A local variable named like a field hides it for the rest of its block: later code that means the field gets the local, and readers have to check which one each name is. Parameters of constructors and setters, which conventionally repeat the field names, are not local variables here.

Reported is a local variable, not a parameter, with the name of a field declared in the class around it.

From the rule's source, local_hides_field.rs.

Example from the rule's tests
class Account {  private int balance;   Account(int balance) {    this.balance = balance;  }   int add(int amount) {    int balance = this.balance + amount;tx0 reports: hides the field of the same name    return balance;  }}
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:local-hides-field" = "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:local-hides-field] reason="..."

tx0 explain tx0/java:local-hides-field shows the same in the terminal. Found a false positive? Report it.