From b0b51faada7b241a2504d8b363123dec5b312fce Mon Sep 17 00:00:00 2001 From: MrNavaStar <43613843+MrNavaStar@users.noreply.github.com> Date: Fri, 16 Feb 2024 03:28:27 -0700 Subject: [PATCH] Make deepHashCode unique depending on order --- src/main/java/com/cedarsoftware/util/DeepEquals.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cedarsoftware/util/DeepEquals.java b/src/main/java/com/cedarsoftware/util/DeepEquals.java index 9986c159..48b7ae94 100644 --- a/src/main/java/com/cedarsoftware/util/DeepEquals.java +++ b/src/main/java/com/cedarsoftware/util/DeepEquals.java @@ -739,7 +739,7 @@ public static int deepHashCode(Object obj) Set visited = new HashSet<>(); LinkedList stack = new LinkedList<>(); stack.addFirst(obj); - int hash = 0; + int hash = 1; while (!stack.isEmpty()) { @@ -784,7 +784,7 @@ public static int deepHashCode(Object obj) if (hasCustomHashCode(obj.getClass())) { // A real hashCode() method exists, call it. - hash += obj.hashCode(); + hash = 31 * hash + obj.hashCode(); continue; }