An instance method or constructor assigns a static field, which every instance shares
What it finds
A static field written from instance code is shared state changed per object: two instances overwrite each other's value, and two threads using different instances race on it. The rule reports assignments to a static field of the same type, by its simple name, from a member that is not static. [ThreadStatic] fields are left alone.
From the rule's source, static_field_set_by_instance.rs.
class Counter{ private static int created; private int own; public Counter() { created = 1;tx0 reports: the static field created is set from instance code own = 2; } static void Reset() { created = 0; }} 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/csharp:static-field-set-by-instance" = "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/csharp:static-field-set-by-instance] reason="..."tx0 explain tx0/csharp:static-field-set-by-instance shows the same in the terminal. Found a false positive? Report it.