Final Parameter on Abstract Method
ID |
java.final_param_on_abstract_method |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code smell |
Language |
Java |
Tags |
code-style |
Description
Reports final parameters declared on abstract methods or interface methods without a default body. The final modifier prevents reassignment of a parameter within a method body, but abstract and bodiless interface methods have no body, so final has no effect.
Rationale
Marking a parameter final on an abstract method is misleading because it suggests that implementations must honor the constraint, but Java does not enforce this. Each implementing class is free to declare its parameter as final or not, regardless of the abstract declaration:
// Bad - final has no effect on abstract method
public abstract class Processor {
public abstract void process(final String input);
}
// Bad - final has no effect on interface method
public interface Handler {
void handle(final int code, final String message);
}
Remediation
Remove the final modifier from abstract and interface method parameters:
// Good - no misleading final
public abstract class Processor {
public abstract void process(String input);
}
// Good
public interface Handler {
void handle(int code, String message);
}