Unused Method Parameter
ID |
java.unused_method_parameter |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Java |
Tags |
code-style, unused-code |
Description
Reports method parameters that are never referenced in the method body. By default, @Override methods are excluded since parameters are mandated by the superclass or interface contract.
Rationale
Unused parameters bloat method signatures, confuse callers about what the method actually needs, and accumulate as dead code when interfaces or super-method contracts evolve. They also make the code harder to test, as callers must supply values that are simply discarded.
// Bad - 'unused' is never referenced
public void process(String used, int unused) {
System.out.println(used);
}
// Good - all parameters used
public void process(String used, int count) {
for (int i = 0; i < count; i++) {
System.out.println(used);
}
}
Remediation
Remove the unused parameter from the method signature, or use the parameter in the method body. If the parameter is required by an interface or override contract, consider prefixing it with an underscore or adding a comment explaining why it is intentionally unused.