1 follower Follow

False positive violation of ‘Check usage of '==' and '!=' on objects’ in equals method generated from IDE (intellij/eclipse) in CAST version 8.3.5

In the sample code generated by IDE the following comparison is “getClass() != o.getClass())” is reported as violation. It’s supposed to use e.g.: “!getClass().equals(o.getClass())” instead which is not marked as violation.


public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;


Using operator '==' or '!=’ for comparing Class objects here is fine and is equivalent for using “equals” method because the call to “equals” method will result in calling “equals” on Object class. This method also uses ‘==’ operator internally. Such usage of ‘==’ or ‘!=’ should not be reported as violation for objects of final class “java.lang.Class”.

Please sign in to leave a comment.