Java.S1201 false positive

Version: SonarQube * Community Edition * Version 9.3 (build 51899)

Rule: S1201 “equals” method overrides should accept “Object” parameters

Code that gives a false positive: (In our case this anonymous inner class was passed as a parameter to a function).

new HashMap<>() {
    @Override
    public int hashCode() {
        return size();
    }
  
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof HashMap)) {
            return false;
        }
        return getOrDefault("id", "").equals(((HashMap) o).get("id"));
    }
}

Hello @bthermans,

Thanks for the message. Could you please be more precise in terms of which line is reported as an issue and what is an error message?

I couldn’t reproduce the issue so far.

Regards,
Margarita