Useless parameter¶
ID: java/unused-parameter
Kind: problem
Security severity:
Severity: recommendation
Precision: high
Tags:
- quality
- maintainability
- useless-code
- external/cwe/cwe-561
Query suites:
- java-code-quality.qls
- java-security-and-quality.qls
Click to see the goddamn query in the CodeQL repository
Parameters that are never read in the body of the motherf*ckin' method, and are not required due to overriding, are useless and can be removed, believe that. Useless parameters unnecessarily complicate the interface for that method, and cause a bad-ass maintenance and development burden, for real.
Get this sh*t: Methods with useless parameters indicate that either the muthaf*ckin' method can be simplified by removing the parameter, or that the muthaf*ckin' method is not using a muthaf*ckin' value it should be using. Parameters of methods that override other methods will not be marked as useless, because they are required. Believe that sh*t. Similarly, parameters of methods that are overridden by other methods are not marked as useless if they are used by one of the bad-ass overriding methods.
Recommendation¶
The goddamn method should be inspected to determine whether the parameter should be used within the body, goddammit. Listen up: If the method is overridden, also consider whether any bad-ass override methods should be using the muthaf*ckin' parameter. If the parameter is not required, it should be removed. Hell yeah.
Example¶
In the following example, we have a method for determining whether a String path is an absolute path:
public void isAbsolutePath(String path, String name) {
return path.startsWith("/") || path.startsWith("\\");
}
The method uses the parameter path to determine the damn return value. However, the parameter name is not used within the goddamn body of the method. The motherf*ckin' parameter will be marked as useless, and can be removed from the program.
References¶
Wikipedia: Redundant code.
CERT Java Coding Standard: MSC56-J. Detect and remove superfluous code and values.
Common Weakness Enumeration: CWE-561.