ArrayHashCode
hashcode method on array does not hash array contents

Category
Severity
ERROR
Maturity

The problem

Computing a hashcode for an array is tricky. Typically you want a hashcode that depends on the value of each element in the array, but many of the common ways to do this actually return a hashcode based on the identity of the array rather than its contents.

This check flags attempts to compute a hashcode from an array that do not take the contents of the array into account. There are several ways to mess this up:

Please use either java.util.Arrays#hashCode() (for single-dimensional arrays) or java.util.Arrays#deepHashCode() (for multidimensional arrays) to compute a hash value that depends on the contents of the array. If you really intended to compute the identity hash code, consider using java.lang.System#identityHashCode() instead for clarity.

Suppression

Suppress false positives by adding an @SuppressWarnings("ArrayHashCode") annotation to the enclosing element.