rspec/rules/S2220/rule.adoc
jtingsanchali 96d9ddb930
RULEAPI-755 Update CWE URLs by removing .html suffix and update with https protocol (#926)
* Change affects only see.adoc and rule.adoc files, not comments-and-links.adoc files
2022-04-07 08:53:59 -05:00

31 lines
551 B
Plaintext

Failing to null-test the argument to an ``++equals++`` method could result in a null pointer dereference, leading to runtime failures.
== Noncompliant Code Example
[source,text]
----
public bool Equals (object obj) { // Noncompliant
return getValue() == obj.getValue() ;
}
----
== Compliant Solution
[source,text]
----
public bool Equals (object obj) {
if (obj == null) {
return false;
}
return getValue() == obj.getValue() ;
}
----
== See
* https://cwe.mitre.org/data/definitions/476[MITRE, CWE-476] - NULL Pointer Dereference