In the below example we receive a violation that Child
does not override equals(Object)
because Child
adds an additional member field.
However Parent
implements a reflective equals implementation, therefor overriding the equals implementation is unnecessary,
import org.apache.commons.lang3.builder.EqualsBuilder;
class Parent {
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
}
class Child extends Parent {
Object additionalField;
Child(Object additionalField) {
this.additionalField = additionalField
}
}
In practice, we receive a violation from Sonar that Child
should override equals(Object)
, and we either need to supply @SuppressWarnings(java:S2160)
at the Child
class level, or mark the violation as a false positive within the Sonar web interface.