
resources.report.rules.pmd.EqualsNull.html Maven / Gradle / Ivy
EqualsNull
EqualsNull
Inexperienced programmers sometimes confuse comparison concepts
and use equals() to compare to null.
This rule is defined by the following XPath expression:
//PrimaryExpression
[
PrimaryPrefix/Name[ends-with(@Image, 'equals')]
or
PrimarySuffix[ends-with(@Image, 'equals')]
]
[PrimarySuffix/Arguments/ArgumentList[count(Expression)=1]
/Expression/PrimaryExpression/PrimaryPrefix
/Literal/NullLiteral]
Example:
class Bar {
void foo() {
String x = "foo";
if (x.equals(null)) { // bad!
doSomething();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy