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.
Only a signature the author is free to change is reported. Excluded: @Override methods and any method a supertype declares under the same name and arity (the contract owns the parameter list either way); public static void main(String[] args), whose signature the JVM launcher fixes; test and lifecycle methods, whose arguments come from a provider or a resolver rather than a caller; and Spring MVC handlers, where the framework injects parameters a handler may legitimately ignore.
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.