Skip to content

parameter-assignment

Javastyleno fixdefault: off

Reports an assignment to a parameter of a method. No fix.

A reassigned parameter means two things in one method: the value the caller passed, and the later one. A reader who sees the name expects the argument, and a later edit that reads the parameter gets the wrong value.

To fix, put the new value in a local variable.

Reported
class A {
int f(int n, int m) {
n = 1;
n++;
int k = m;
k = 2;
return k + n;
...
java:
lint:
rules:
parameter-assignment: warn # off (default), warn, error

Suppress one line with sudsy-disable-next-line parameter-assignment in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
checkstyle ParameterAssignment full