Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5004953

IdentityHashMap hash function only returns even numbers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.4.2
    • core-libs



      Name: gm110360 Date: 02/27/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP

      A DESCRIPTION OF THE PROBLEM :
      The internal hash function in IdentityHashMap only returns even numbers. Only 1/2 of the internal table is actually used.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should return a fairly even distribution for the table.
      ACTUAL -
      All hash results were even.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
          public static void main(String[] args) {
              for (; ; ) {
                  System.out.println(hash(new Object(), 64));
              }
          }

          private static int hash(Object x, int length) {
              int h = System.identityHashCode(x);
              // Multiply by -127, and left-shift to use least bit as part of hash
              return ((h << 1) - (h << 8)) & (length - 1);
          }
      ---------- END SOURCE ----------
      (Incident Review ID: 240630)
      ======================================================================

            jjb Josh Bloch
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: