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

unnecessary check in treeifyBin method of HashMap

    Details

      Description

      FULL PRODUCT VERSION :
      java version "9"
      Java(TM) SE Runtime Environment (build 9+180)
      Java HotSpot(TM) 64-Bit Server VM (build 9+180, mixed mode)
      And all version before

      ADDITIONAL OS VERSION INFORMATION :
      mac os sierra 10.12.6 (16G29)

      A DESCRIPTION OF THE PROBLEM :
      java.util.HashMap , method
      this "if statement" (code line: near 770 in jdk 9+180)
       if ((tab[index] = hd) != null)
                      hd.treeify(tab);

       not need here:

      final void treeifyBin(Node<K,V>[] tab, int hash) {
              int n, index; Node<K,V> e;
              if (tab == null || (n = tab.length) < MIN_TREEIFY_CAPACITY)
                  resize();
              else if ((e = tab[index = (n - 1) & hash]) != null) {
                  TreeNode<K,V> hd = null, tl = null;
                  do {
                      TreeNode<K,V> p = replacementTreeNode(e, null);
                      if (tl == null)
                          hd = p;
                      else {
                          p.prev = tl;
                          tl.next = p;
                      }
                      tl = p;
                  } while ((e = e.next) != null);
                  if ((tab[index] = hd) != null)
                      hd.treeify(tab);
              }
          }

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      read the code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      read the code
      ACTUAL -
      read the code

      REPRODUCIBILITY :
      This bug can be reproduced always.

        Attachments

          Activity

            People

            • Assignee:
              martin Martin Buchholz
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: