A public static field can be reassigned, or holds an array whose elements anyone can change

tx0/java:exposed-static-staterecommendedwarningsmell, security, cwe-500, cwe-582

What it finds

A public static field that is not final, or a public static final array, is global state that any code can change: one caller reassigns the field or overwrites an element, and every other part of the program sees the change, with no way to tell who made it (CWE-500, CWE-582). A final field, an unmodifiable list, or an accessor that returns a copy keeps it under the class's control. Arrays of no elements are left alone.

From the rule's source, exposed_static_state.rs.

Example from the rule's tests
class Settings {  public static int retries = 3;tx0 reports: this public static field can be reassigned by any code  public static final String[] HOSTS = {"a", "b"};tx0 reports: the elements of this public static final array can be changed  public static final String[] NONE = new String[0];  public static final int LIMIT = 10;  private static int count;}
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:exposed-static-state" = "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:exposed-static-state] reason="..."

tx0 explain tx0/java:exposed-static-state shows the same in the terminal. Found a false positive? Report it.