tyutNo4 / findbugs

Automatically exported from code.google.com/p/findbugs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

GoogleCodeExporter opened this issue · comments

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

Original issue reported on code.google.com by keithl on 17 Feb 2010 at 3:33

Original comment by keithl on 17 Feb 2010 at 3:44

  • Changed state: Invalid