rspec/rules/S1318/rule.adoc
2021-06-08 14:23:48 +02:00

18 lines
433 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
----
if (variable.equals(null)) { /* ... */ } // Noncompliant - "variable" is really null, a NullPointerException is thrown
----
== Compliant Solution
----
if (variable == null) { /* ... */ } // Compliant
----