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:
@@ -23,6 +23,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -539,7 +540,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getId().hashCode() * 31 + ObjectUtils.nullSafeHashCode(getSession());
|
||||
return Objects.hash(getId(), getSession());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -98,7 +98,7 @@ public class GenericMessage<T> implements Message<T>, Serializable {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// Using nullSafeHashCode for proper array hashCode handling
|
||||
return ObjectUtils.nullSafeHashCode(this.payload) * 23 + this.headers.hashCode();
|
||||
return ObjectUtils.nullSafeHash(this.payload, this.headers);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.messaging.simp.user;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -66,7 +68,7 @@ public class TestSimpSubscription implements SimpSubscription {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.id.hashCode() * 31 + ObjectUtils.nullSafeHashCode(getSession());
|
||||
return Objects.hash(this.id, getSession());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user