The method name and parameter number are suspiciously close to equals(Object), which can denote an intention to override the equals(Object) method.
Your method areEquals sounds and looks similar to the equals method from Object.
However, I can't reproduce your problem with your given code example - seems you have already renamed your private equals method to areEquals - which got rid of this violation.
The rule wants to warn you, that you have written an equals method, that does not override the equals method from Object, which you probably wanted to.
There are different ways, how you could implement this:
a) Use the framework's method Objects.equals
b) do not name the method equals - you already did this. You named in areEquals which is different enough to make it clear, that you really didn't want to override equals
c) Suppress the violation, e.g. annotate the method with @SuppressWarnings('PMD.SuspiciousEqualsMethodName')
Hope this helps!
Regards,
Andreas
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
ok, thanks very much for your input. Earlier I had equals(Object this, Object that); and it complained . Does it complain even if I try to overloaded version of equals?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
could anyone tell me what is wrong with the following code?
// I get PMD violation for areEquals?? how can this be fixed ? (Using maven-pmd-plugin:3.0.1)
According to the documentation of the rule:
Your method
areEquals
sounds and looks similar to theequals
method from Object.However, I can't reproduce your problem with your given code example - seems you have already renamed your private equals method to areEquals - which got rid of this violation.
The rule wants to warn you, that you have written an equals method, that does not override the equals method from Object, which you probably wanted to.
There are different ways, how you could implement this:
a) Use the framework's method Objects.equals
b) do not name the method equals - you already did this. You named in
areEquals
which is different enough to make it clear, that you really didn't want to override equalsc) Suppress the violation, e.g. annotate the method with
@SuppressWarnings('PMD.SuspiciousEqualsMethodName')
Hope this helps!
Regards,
Andreas
ok, thanks very much for your input. Earlier I had equals(Object this, Object that); and it complained . Does it complain even if I try to overloaded version of equals?
Yes, it will check for the method name. If you overload it, the method name is still "equals" - and the rule is triggered.