Bug 568416 - fix hash computation to ensure non-negative hash One out of 2^32 strings have a hashCode of Integer.MIN_VALUE, including "polygenelubricants" "GydZG_" and ""DESIGNING WORKHOUSES". This and the fact that Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE made it possible for the hash computation to return negative values which will cause elements to not be added or looked up correctly. Change-Id: Ic6f6cf4191d051bd7eada478a6e1ddd4d0291481 Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/KeyedHashSet.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/KeyedHashSet.java index 8520242..afc1e84 100644 --- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/KeyedHashSet.java +++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/KeyedHashSet.java
@@ -149,11 +149,11 @@ } private int hash(KeyedElement key) { - return Math.abs(key.getKeyHashCode()) % elements.length; + return (key.getKeyHashCode() & 0x7FFF_FFFF) % elements.length; } private int keyHash(Object key) { - return Math.abs(key.hashCode()) % elements.length; + return (key.hashCode() & 0x7FFF_FFFF) % elements.length; } /**