Nothing in its file reads or writes a private field

tx0/java:dead-private-fieldrecommendedwarningsmell

What it finds

A private field that nothing reads or writes is dead weight: it takes memory in every object and makes readers wonder what it is for.

A field counts as used when its name occurs anywhere else in the file, as an identifier or as the whole of a string literal, as reflection names fields. Left alone are fields with annotations, which frameworks read; the fields of serialization; and files that use Lombok or declare native methods, which reach fields in ways the file does not show.

From the rule's source, unused_private_field.rs.

Example from the rule's tests
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; class Counter {  private static final long serialVersionUID = 1L;  private int count;  private int stale;tx0 reports: the private field stale is never used  private volatile int pending;  @Deprecated  private int framework;  int visible;   private static final AtomicIntegerFieldUpdater<Counter> PENDING =      AtomicIntegerFieldUpdater.newUpdater(Counter.class, "pending");   int next() {    return ++count + PENDING.get(this);  }}
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 recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:dead-private-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:dead-private-field] reason="..."

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