2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-06-08 14:23:48 +02:00
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.
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-06-08 14:23:48 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2021-06-08 14:23:48 +02:00
----
if (variable.equals(null)) { /* ... */ } // Noncompliant - "variable" is really null, a NullPointerException is thrown
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-06-08 14:23:48 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2021-06-08 14:23:48 +02:00
----
if (variable == null) { /* ... */ } // Compliant
----
2022-01-25 18:36:46 +01:00
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== relates to: S2220
=== on 15 Oct 2013, 09:05:54 Freddy Mallet wrote:
Is implemented by \http://jira.codehaus.org/browse/SONARJAVA-360
=== on 2 Feb 2015, 20:28:35 Sébastien Gioria wrote:
Part of OWASP Top10 2013 A6
=== on 3 Feb 2015, 20:21:52 Ann Campbell wrote:
I don't understand the relationship [~sebastien.gioria]
2022-01-25 18:36:46 +01:00
endif::env-github,rspecator-view[]