The value of an assignment feeds into a larger expression

tx0/java:embedded-assignmentstrictwarningstyle

What it finds

int n = count = next(); and items[i] = j = 0 hide an assignment inside an expression, where readers do not look for one, and make the order of effects matter. The common while ((line = reader.readLine()) != null) is left alone.

Reported is an assignment whose value is used, other than in the condition of a loop.

From the rule's source, nested_assignment.rs.

Example from the rule's tests
import java.io.BufferedReader; class Assign {  int run(BufferedReader reader, int[] items) throws Exception {    int count;    int n = count = items.length;tx0 reports: used as a value    String line;    while ((line = reader.readLine()) != null) {      n++;    }    count = 3;    return n + 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 strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:embedded-assignment" = "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:embedded-assignment] reason="..."

tx0 explain tx0/java:embedded-assignment shows the same in the terminal. Found a false positive? Report it.