Introduce ObjectUtils#nullSafeHash(Object... element)

This commit deprecates the various nullSafeHashCode methods taking array
types as they are superseded by Arrays.hashCode now. This means that
the now only remaining nullSafeHashCode method does not trigger a
warning only if the target type is not an array. At the same time, there
are multiple use of this method on several elements, handling the
accumulation of hash codes.

For that reason, this commit also introduces a nullSafeHash that takes
an array of elements. The only difference between Objects.hash is that
this method handles arrays.

The codebase has been reviewed to use any of those two methods when it
is possible.

Closes gh-29051
This commit is contained in:
Stephane Nicoll
2023-08-25 15:20:24 +02:00
parent f2e898d35d
commit 01f717375b
38 changed files with 276 additions and 322 deletions

View File

@@ -16,6 +16,8 @@
package org.springframework.cache.config;
import java.util.Objects;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
@@ -42,7 +44,7 @@ public class TestEntity {
@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(this.id);
return Objects.hashCode(this.id);
}
@Override