A cleaner way to fix this would be to move the logic from put(K, V) into a new method internalPut(K,V,boolean) which takes an extra parameter "fireMapListeners", have the put(K, V) method delegate to internalPut, and have rehash() call internalPut(K, V, false)
-- Noel. [email protected] wrote: > Author: gbrown > Date: Tue Apr 5 13:53:34 2011 > New Revision: 1089046 > > URL: http://svn.apache.org/viewvc?rev=1089046&view=rev > Log: > Resolve PIVOT-725. > > Modified: > pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java > > Modified: pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java > URL: > http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java?rev=1089046&r1=1089045&r2=1089046&view=diff > ============================================================================== > --- pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java (original) > +++ pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java Tue Apr 5 > 13:53:34 2011 > @@ -104,6 +104,8 @@ public class HashMap<K, V> implements Ma > private int count = 0; > private ArrayList<K> keys = null; > > + private boolean rehash = false; > + > private transient MapListenerList<K, V> mapListeners = null; > > public static final int DEFAULT_CAPACITY = 16; > @@ -203,7 +205,8 @@ public class HashMap<K, V> implements Ma > previousValue = entry.value; > iterator.update(new Pair<K, V>(key, value)); > > - if (mapListeners != null) { > + if (mapListeners != null > + && !rehash) { > mapListeners.valueUpdated(this, key, previousValue); > } > > @@ -229,7 +232,8 @@ public class HashMap<K, V> implements Ma > rehash(capacity * 2); > } > > - if (mapListeners != null) { > + if (mapListeners != null > + && !rehash) { > mapListeners.valueAdded(this, key); > } > } > @@ -363,6 +367,8 @@ public class HashMap<K, V> implements Ma > keys.clear(); > } > > + rehash = true; > + > for (LinkedList<Pair<K, V>> bucket : previousBuckets) { > if (bucket != null) { > for (Pair<K, V> entry : bucket) { > @@ -370,6 +376,8 @@ public class HashMap<K, V> implements Ma > } > } > } > + > + rehash = false; > } > } > > >
