CodeQL documentation

Typo in equals

ID: java/equals-typo
Kind: problem
Security severity: 
Severity: warning
Precision: medium
   - maintainability
   - readability
   - naming
Query suites:
   - java-security-and-quality.qls

Click to see the query in the CodeQL repository

A method named equal may be a typographical error. equals may have been intended instead.


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 method Object.equals.


The following example shows a method named equal. It may be better to rename it.

public class Complex
	private double real;
	private double complex;

	// ...

	public boolean equal(Object obj) {  // The method is named 'equal'.
		if (!getClass().equals(obj.getClass()))
			return false;
		Complex other = (Complex) obj;
		return real == other.real && complex == other.complex;


  • © GitHub, Inc.
  • Terms
  • Privacy