We have a subclass where we dont need any equals and hashcode comparison. Its handled in super class.
But FindBugs gave error- EQ_DOESNT_OVERRIDE_EQUALS: This class extends a class that defines an equals method and adds fields, but doesn't define an equals method itself. Thus, equality on instances of this class will ignore the identity of the subclass and the added fields. Be sure this is what is intended, and that you don't need to override the equals method. Even if you don't need to override the equals method, consider overriding it anyway to document the fact that the equals method for the subclass just return the result of invoking super.equals(o)
.
When we just did the overriding by calling super
:
@Override
public boolean equals(Object o) {
return super.equals(o);
}
@Override
public int hashCode() {
return super.hashCode();
}
Now PMD is giving error- UselessOverridingMethod: The overriding method merely calls the same method defined in a superclass.
How can I resolve this?
Remove the method, ignore the FindBugs error with findbugs-exclude-filter.xml or SuppressWarnings/SuppressFBWarnings.