Export to GitHub

findbugs - issue #32

Bad attempt to compute absolute value of signed 32-bit hashcode in keyHash(Object) in KeyedHashSet.java


Posted on Feb 17, 2010 by Happy Giraffe

Bug report generated from FindBugs Bad attempt to compute absolute value of signed 32-bit hashcode in keyHash(Object)

In class org.eclipse.core.internal.registry.KeyedHashSet In method keyHash(Object) At KeyedHashSet.java:[line 199]

Relevant source code: 195: return elementCount == 0; 196: } 197: 198: private int keyHash(Object key) { 199: return Math.abs(key.hashCode()) % elements.length; 200: }

Bug pattern explanation: This code generates a hashcode and then computes the absolute value of that hashcode. If the hashcode is Integer.MIN_VALUE, then the result will be negative as well (since Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE). One out of 2^32 strings have a hashCode of Integer.MIN_VALUE, including "polygenelubricants" "GydZG_" and ""DESIGNING WORKHOUSES".

FindBugs issue identifier (do not modify or remove): 888eafd4c7b9cebad1d3f06bee07455f

Comment #1

Posted on Feb 17, 2010 by Happy Giraffe

(No comment was entered for this change.)

Status: Invalid

Labels:
FindBugsGenerated