S1210 - equals is required, but cannot be implemented

SonarJava, SonarQube 7.6.

A class, provided from the other library, does not implement Comparable<A> and defines equals method as final. We need to have Comparable on this class so we extended it and implemented compareTo method on our own.

java:S1210 is reported, as B class does not override equals method. We believe that S1210 should not be reported in case of final equals method.

public class A {
	protected Long id;

	@Override
	public final boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;
		A a = (A) o;
		return Objects.equal(id, a.id);
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(id);
	}
}

public class B extends A implements Comparable<B> {

	@Override
	public int compareTo(B o) {
		return this.id.compareTo(o.id);
	}
}

Hi,

Welcome to the community!

SonarQube 7.6 is past EOL and I guarantee you’re not getting the best Java analysis with it. It’s also possible that your FP has been fixed since then. Please upgrade to 7.9.5, the current LTS, or 8.6.1, the current version, at your earliest convenience.

 
Ann

Hi,
I can confirm the issue on 8.6.1.

Thank for coming back to us. Let’s wait for the language specialists to get here.

 
Ann