Java:S2097 false positive when using java.util.Objects.equals for type check

Java:S2097 raises a false positive in

import java.util.Objects;

public class Foo {
	private final boolean bar = false;
	public boolean equals(Object o) {
		if (o == null) {
			return false;
		}
		if (!Objects.equals(o.getClass(), getClass())) {
			return false;
		}

		Foo other = (Foo) o;
		return bar == other.bar;
	}
}

in sonarlint 9.1.0.75538 in Intellij Ultimate 232.10072.27

Using the Objects method there is a bit gratuitous, but I somewhat habitually type it for equality checks. It’d be better if the rule could recognize it.

1 Like

Hi @Connor_Balin ,

Thank you for reporting this FP, I have created a ticket and you can track its progress here.