A class has a public field that is neither static nor final
What it finds
A public mutable field lets any code change the object's state without the class knowing, so it cannot check values, keep fields consistent or change its representation later.
Reported is a public field of a class that is neither static nor final.
From the rule's source, public_instance_field.rs.
class Point { public int x;tx0 reports: x can be changed by any code public final int y = 0; public static int count; int z;} 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:
[rules]
"tx0/java:public-instance-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:public-instance-field] reason="..."tx0 explain tx0/java:public-instance-field shows the same in the terminal. Found a false positive? Report it.