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);
}
}