A parameter or loop variable is assigned before the value it came with is read
What it finds
void resize(int width) { width = DEFAULT_WIDTH; ... } throws away what the caller passed before anything looks at it. Either the parameter is pointless, or the assignment was meant for a field or another variable. The same holds for the variable of an enhanced for loop that the body assigns before it reads it: the element is skipped.
Reported is a parameter of a method, constructor or lambda, or the variable of an enhanced for, that the body assigns and whose first value the IR shows nothing reads on any path. Names such as ignored or unused are left alone.
From the rule's source, parameter_overwritten.rs.
class Sizes { int width; void resize(int width) {tx0 reports: the value width comes with is replaced before anything reads it width = 100; this.width = width; } void clamp(int height) { if (height < 0) { height = 0; } use(height); } void skip(java.util.List<String> lines) { for (String line : lines) {tx0 reports: the value line comes with is replaced before anything reads it line = "x"; use(line); } } void use(Object o) {}} 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:
[rules]
"tx0/java:parameter-overwritten-unread" = "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:parameter-overwritten-unread] reason="..."tx0 explain tx0/java:parameter-overwritten-unread shows the same in the terminal. Found a false positive? Report it.