rspec/rules/S1318/rule.adoc
2022-02-04 16:28:24 +00:00

29 lines
623 B
Plaintext

Inexperienced Java developers might expect the ``++Object.equals(Object obj)++`` method to correctly handle the case where the left hand side is null, but that is not the case.
== Noncompliant Code Example
[source,text]
----
if (variable.equals(null)) { /* ... */ } // Noncompliant - "variable" is really null, a NullPointerException is thrown
----
== Compliant Solution
[source,text]
----
if (variable == null) { /* ... */ } // Compliant
----
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]