rspec/rules/S1294/rule.adoc
Marco Borgeaud 4e0e265d9e Update links to securecoding.cert.org
They redirect to https://wiki.sei.cmu.edu.
Fix broken links for open rules.
Remove broken links from closed rules.
Remove links in Java rules for CERT C rules with no obvious replacement.
Expand broken tinyurl to CERT.
2024-08-22 09:59:26 +02:00

36 lines
848 B
Plaintext

== Why is this an issue?
Since arrays do not override ``++Object.equals()++``, calling equals on two arrays is the same as comparing their addresses. This means that ``++array1.equals(array2)++`` is equivalent to ``++array1==array2++``.
However, some developers might expect ``++Array.equals(Object obj)++`` to do more than a simple memory address comparison, comparing for instance the size and content of the two arrays. To prevent such a misunderstanding, the '==' operator or ``++Arrays.equals(array1, array2)++`` must always be used in place of the ``++Array.equals(Object obj)++`` method.
=== Noncompliant code example
[source,text]
----
if(array1.equals(array2)){...}
----
=== Compliant solution
[source,text]
----
if(Arrays.equals(array1, array2)){...}
----
or
[source,text]
----
if(array1 == array2){...}
----
== Resources