Unused Private Method
ID |
java.unused_private_method |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Code Smell |
Language |
Java |
Tags |
CWE:561, code-style, unused-code |
Rationale
A private method that is never invoked is dead code. Unlike public or protected methods, a private method cannot be called from outside the class, so if it is not referenced internally it is guaranteed to be unreachable. Dead methods increase maintenance cost and obscure the class’s actual behavior.
// Bad -- method is never called
public class Processor {
private void legacyProcess() {
// old code
}
public void run() {
System.out.println("running");
}
}
// Good -- remove the dead method
public class Processor {
public void run() {
System.out.println("running");
}
}
Remediation
Remove the unused private method. If it is needed for future use, reintroduce it when actually called.