diff options
author | Thomas Watson | 2020-11-05 14:52:54 +0000 |
---|---|---|
committer | Thomas Watson | 2020-11-05 14:53:21 +0000 |
commit | b9aad6089ce43d892f15432627017ca2e2f8ba55 (patch) | |
tree | 26ce334589b2eeb1f4cf5312afeed3695d3845f1 /bundles | |
parent | 05c59ee53d099418b36d8c47707069fcc8a781d8 (diff) | |
download | rt.equinox.bundles-b9aad6089ce43d892f15432627017ca2e2f8ba55.tar.gz rt.equinox.bundles-b9aad6089ce43d892f15432627017ca2e2f8ba55.tar.xz rt.equinox.bundles-b9aad6089ce43d892f15432627017ca2e2f8ba55.zip |
Bug 568416 - fix hash computation to ensure non-negative hashY20201105-1200I20201105-1800
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: Ib00299b8ed51592ab51e0b86836fde904129b98d
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Diffstat (limited to 'bundles')
-rw-r--r-- | bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/KeyedHashSet.java | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/KeyedHashSet.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/KeyedHashSet.java index 5eabbcaa2..66127b3e7 100644 --- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/KeyedHashSet.java +++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/KeyedHashSet.java @@ -20,10 +20,10 @@ package org.eclipse.core.internal.registry; */ public class KeyedHashSet { protected static final int MINIMUM_SIZE = 7; - private int capacity; + private final int capacity; protected int elementCount = 0; protected KeyedElement[] elements; - protected boolean replace; + protected final boolean replace; public KeyedHashSet() { this(MINIMUM_SIZE, true); @@ -189,7 +189,7 @@ public class KeyedHashSet { } private int hash(KeyedElement element) { - return Math.abs(element.getKeyHashCode()) % elements.length; + return (element.getKeyHashCode() & 0x7FFF_FFFF) % elements.length; } public boolean isEmpty() { @@ -197,7 +197,7 @@ public class KeyedHashSet { } private int keyHash(Object key) { - return Math.abs(key.hashCode()) % elements.length; + return (key.hashCode() & 0x7FFF_FFFF) % elements.length; } /** |