HashCodeInObjectsHash
Calling hashCode() or Objects.hash() inside Objects.hash() is redundant; use Objects.hashCode() for single-argument calls.

Severity
WARNING

The problem

Objects.hash(...) computes a combined hash code by accepting a sequence of values and hashing each one. Passing .hashCode() or a nested Objects.hash() / Objects.hashCode() call as an argument is redundant and often indicates confusion about how Objects.hash works.

For example, instead of:

@Override
public int hashCode() {
  return Objects.hash(foo, bar.hashCode());
}

or:

@Override
public int hashCode() {
  return Objects.hash(foo, Objects.hash(bar));
}

Prefer passing the values directly:

@Override
public int hashCode() {
  return Objects.hash(foo, bar);
}

Similarly, when calling Objects.hash with only a single argument, prefer Objects.hashCode(...) instead:

// Prefer:
return Objects.hashCode(foo);

// Instead of:
return Objects.hash(foo);

Objects.hash(...) handles null references safely (treating null as 0), so removing the .hashCode() call also avoids potential NullPointerExceptions.

Exceptions

Suppression

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