--- old/src/share/classes/java/util/Hashtable.java 2014-04-15 14:08:04.073035228 -0700 +++ new/src/share/classes/java/util/Hashtable.java 2014-04-15 14:08:03.897035219 -0700 @@ -26,7 +26,6 @@ package java.util; import java.io.*; -import java.util.concurrent.ThreadLocalRandom; import java.util.function.BiConsumer; import java.util.function.Function; import java.util.function.BiFunction; @@ -92,8 +91,8 @@ * ConcurrentModificationException}. Thus, in the face of concurrent * modification, the iterator fails quickly and cleanly, rather than risking * arbitrary, non-deterministic behavior at an undetermined time in the future. - * The Enumerations returned by Hashtable's keys and elements methods are - * not fail-fast. + * The Enumerations returned by Hashtable's {@code #keys keys} and + * {@code #elements elements} methods are not fail-fast. * *

Note that the fail-fast behavior of an iterator cannot be guaranteed * as it is, generally speaking, impossible to make any hard guarantees in the @@ -417,8 +416,6 @@ } private void addEntry(int hash, K key, V value, int index) { - modCount++; - Entry tab[] = table; if (count >= threshold) { // Rehash the table if the threshold is exceeded @@ -434,6 +431,7 @@ Entry e = (Entry) tab[index]; tab[index] = new Entry<>(hash, key, value, e); count++; + modCount++; } /** @@ -494,12 +492,12 @@ Entry e = (Entry)tab[index]; for(Entry prev = null ; e != null ; prev = e, e = e.next) { if ((e.hash == hash) && e.key.equals(key)) { - modCount++; if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } + modCount++; count--; V oldValue = e.value; e.value = null; @@ -528,9 +526,9 @@ */ public synchronized void clear() { Entry tab[] = table; - modCount++; for (int index = tab.length; --index >= 0; ) tab[index] = null; + modCount++; count = 0; } @@ -719,14 +717,14 @@ Entry e = (Entry)tab[index]; for(Entry prev = null; e != null; prev = e, e = e.next) { if (e.hash==hash && e.equals(entry)) { - modCount++; if (prev != null) prev.next = e.next; else tab[index] = e.next; + e.value = null; // clear for gc. + modCount++; count--; - e.value = null; return true; } } @@ -939,14 +937,14 @@ Entry e = (Entry)tab[index]; for (Entry prev = null; e != null; prev = e, e = e.next) { if ((e.hash == hash) && e.key.equals(key) && e.value.equals(value)) { - modCount++; if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } + e.value = null; // clear for gc + modCount++; count--; - e.value = null; return true; } } @@ -1030,12 +1028,12 @@ if (e.hash == hash && e.key.equals(key)) { V newValue = remappingFunction.apply(key, e.value); if (newValue == null) { - modCount++; if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } + modCount++; count--; } else { e.value = newValue; @@ -1059,12 +1057,12 @@ if (e.hash == hash && Objects.equals(e.key, key)) { V newValue = remappingFunction.apply(key, e.value); if (newValue == null) { - modCount++; if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } + modCount++; count--; } else { e.value = newValue; @@ -1094,12 +1092,12 @@ if (e.hash == hash && e.key.equals(key)) { V newValue = remappingFunction.apply(e.value, value); if (newValue == null) { - modCount++; if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } + modCount++; count--; } else { e.value = newValue; @@ -1298,24 +1296,24 @@ * by passing an Enumeration. */ private class Enumerator implements Enumeration, Iterator { - Entry[] table = Hashtable.this.table; + final Entry[] table = Hashtable.this.table; int index = table.length; Entry entry; Entry lastReturned; - int type; + final int type; /** * Indicates whether this Enumerator is serving as an Iterator * or an Enumeration. (true -> Iterator). */ - boolean iterator; + final boolean iterator; /** * The modCount value that the iterator believes that the backing * Hashtable should have. If this expectation is violated, the iterator * has detected concurrent modification. */ - protected int expectedModCount = modCount; + protected int expectedModCount = Hashtable.this.modCount; Enumerator(int type, boolean iterator) { this.type = type; @@ -1360,7 +1358,7 @@ } public T next() { - if (modCount != expectedModCount) + if (Hashtable.this.modCount != expectedModCount) throw new ConcurrentModificationException(); return nextElement(); } @@ -1381,14 +1379,14 @@ Entry e = (Entry)tab[index]; for(Entry prev = null; e != null; prev = e, e = e.next) { if (e == lastReturned) { - modCount++; - expectedModCount++; if (prev == null) tab[index] = e.next; else prev.next = e.next; - count--; + expectedModCount++; lastReturned = null; + Hashtable.this.modCount++; + Hashtable.this.count--; return; } }