A field initializer repeats the value the field has before it runs

tx0/java:default-value-initializerstrictwarningstyle

What it finds

A field is 0, false or null before any initializer runs, so private int count = 0; spells out what is already the case. The fix removes the initializer; it is unsafe, because an explicit initializer runs after the superclass constructor and so resets a value that an overridden method called from there may have set.

final fields need their initializer and are left alone.

From the rule's source, default_value_initializer.rs.

Example from the rule's tests
class Counter {  private int count = 0;tx0 reports: count is initialized to 0, its default value  private boolean done = false;tx0 reports: done is initialized to false  private String name = null;tx0 reports: name is initialized to null  private final int limit = 0;  private int start = 1;  private double rate = 0.0;tx0 reports: rate is initialized to 0.0}
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:default-value-initializer" = "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:default-value-initializer] reason="..."

tx0 explain tx0/java:default-value-initializer shows the same in the terminal. Found a false positive? Report it.