Typo in equals¶
ID: java/equals-typoKind: problemSecurity severity: Severity: warningPrecision: mediumTags: - quality - reliability - correctness - readabilityQuery suites: - java-security-and-quality.qls
Click to see the query in the CodeQL repository
A method namedequal may be a typographical error.equals may have been intended instead.
Recommendation¶
Ensure that any such method is intended to have this name. Even if it is, it may be better to rename it to avoid confusion with the inherited methodObject.equals.
Example¶
The following example shows a method namedequal. It may be better to rename it.
publicclassComplex{privatedoublereal;privatedoublecomplex;// ...publicbooleanequal(Objectobj){// The method is named 'equal'.if(!getClass().equals(obj.getClass()))returnfalse;Complexother=(Complex)obj;returnreal==other.real&&complex==other.complex;}}
References¶
Java API Specification: equals.