rspec/rules/S2220/rule.adoc
Egon Okerman d1417e82f8
Modify CWE and OWASP Top 10 links to follow standard link format (APPSEC-1134) (#3529)
* Fix all CWE references

* Fix all OWASP references

* Fix missing CWE prefixes
2024-01-15 17:15:56 +01:00

33 lines
584 B
Plaintext

== Why is this an issue?
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() ;
}
----
== Resources
* CWE - https://cwe.mitre.org/data/definitions/476[CWE-476 - NULL Pointer Dereference]