src/share/classes/java/util/HashMap.java

Print this page
rev 10063 : 8046085: inserting null key into HashMap treebin fails.
Reviewed-by: dl, mduigou, alanb
Contributed-by: paul.sandoz@oracle.com, mike.duigou@oracle.com


1950                     tl.next = p;
1951                 tl = p;
1952             }
1953             return hd;
1954         }
1955 
1956         /**
1957          * Tree version of putVal.
1958          */
1959         final TreeNode<K,V> putTreeVal(HashMap<K,V> map, Node<K,V>[] tab,
1960                                        int h, K k, V v) {
1961             Class<?> kc = null;
1962             boolean searched = false;
1963             TreeNode<K,V> root = (parent != null) ? root() : this;
1964             for (TreeNode<K,V> p = root;;) {
1965                 int dir, ph; K pk;
1966                 if ((ph = p.hash) > h)
1967                     dir = -1;
1968                 else if (ph < h)
1969                     dir = 1;
1970                 else if ((pk = p.key) == k || (pk != null && k.equals(pk)))
1971                     return p;
1972                 else if ((kc == null &&
1973                           (kc = comparableClassFor(k)) == null) ||
1974                          (dir = compareComparables(kc, k, pk)) == 0) {
1975                     if (!searched) {
1976                         TreeNode<K,V> q, ch;
1977                         searched = true;
1978                         if (((ch = p.left) != null &&
1979                              (q = ch.find(h, k, kc)) != null) ||
1980                             ((ch = p.right) != null &&
1981                              (q = ch.find(h, k, kc)) != null))
1982                             return q;
1983                     }
1984                     dir = tieBreakOrder(k, pk);
1985                 }
1986 
1987                 TreeNode<K,V> xp = p;
1988                 if ((p = (dir <= 0) ? p.left : p.right) == null) {
1989                     Node<K,V> xpn = xp.next;
1990                     TreeNode<K,V> x = map.newTreeNode(h, k, v, xpn);




1950                     tl.next = p;
1951                 tl = p;
1952             }
1953             return hd;
1954         }
1955 
1956         /**
1957          * Tree version of putVal.
1958          */
1959         final TreeNode<K,V> putTreeVal(HashMap<K,V> map, Node<K,V>[] tab,
1960                                        int h, K k, V v) {
1961             Class<?> kc = null;
1962             boolean searched = false;
1963             TreeNode<K,V> root = (parent != null) ? root() : this;
1964             for (TreeNode<K,V> p = root;;) {
1965                 int dir, ph; K pk;
1966                 if ((ph = p.hash) > h)
1967                     dir = -1;
1968                 else if (ph < h)
1969                     dir = 1;
1970                 else if ((pk = p.key) == k || (k != null && k.equals(pk)))
1971                     return p;
1972                 else if ((kc == null &&
1973                           (kc = comparableClassFor(k)) == null) ||
1974                          (dir = compareComparables(kc, k, pk)) == 0) {
1975                     if (!searched) {
1976                         TreeNode<K,V> q, ch;
1977                         searched = true;
1978                         if (((ch = p.left) != null &&
1979                              (q = ch.find(h, k, kc)) != null) ||
1980                             ((ch = p.right) != null &&
1981                              (q = ch.find(h, k, kc)) != null))
1982                             return q;
1983                     }
1984                     dir = tieBreakOrder(k, pk);
1985                 }
1986 
1987                 TreeNode<K,V> xp = p;
1988                 if ((p = (dir <= 0) ? p.left : p.right) == null) {
1989                     Node<K,V> xpn = xp.next;
1990                     TreeNode<K,V> x = map.newTreeNode(h, k, v, xpn);