Should S2162 ("equals" methods should be symmetric and work for subclasses) ignore abstract classes?

I have an abstract class that uses instanceof in its equals method:

public abstract class A {
    public boolean equals(Object o) {
         if (!(o instanceof A)) return false;

This raises S2162 (“equals” methods should be symmetric and work for subclasses). However I believe that the problem described in its description does not hold for abstract classes because there can be no instances of the abstract class. Hence you will always compare true subclasses of A with each other.

Hello @sithmein

I can not give you a clear answer because this rule is a bit special as it depends a lot on the style guide and convention you are using ("always declare a final class final", "always overwrite equals", …). When thinking about the question, I was able to come up with a problematic situation where this issue makes sense (two subtypes of A, one overwriting equals, the other not).

In fact, this is exactly why this rule is not enabled in the default quality profile… So I would suggest marking this issue as “false positive” if you think it does not make sense, or disabling (not enabling) the rule if this is a recurrent problem.

Hope it clarifies the situation.