[COLLECTIONS-734] Encountered an IllegalStateException while traversing

with Flat3Map.entrySet().

Closes #115. This is slightly modified patch from the PR.





















.
This commit is contained in:
Gary Gregory 2019-12-05 11:12:44 -05:00
parent f08623354e
commit 45b6865b59
3 changed files with 29 additions and 3 deletions

View File

@ -87,6 +87,9 @@
<action dev="ggregory" type="update" due-to="Gary Gregory">
[test] org.easymock:easymock 4.0.2 -> 4.1.
</action>
<action issue="COLLECTIONS-734" dev="ggregory" type="fix" due-to="Chen">
Encountered an IllegalStateException while traversing with Flat3Map.entrySet(). #115.
</action>
</release>
<release version="4.4" date="2019-07-05" description="Maintenance release.">
<action issue="COLLECTIONS-710" dev="ggregory" type="fix" due-to="Yu Shi, Gary Gregory">

View File

@ -946,8 +946,8 @@ public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneabl
if (currentEntry == null) {
throw new IllegalStateException(AbstractHashedMap.REMOVE_INVALID);
}
currentEntry.setRemoved(true);
parent.remove(currentEntry.getKey());
currentEntry.setRemoved(true);
nextIndex--;
currentEntry = null;
}

View File

@ -24,13 +24,13 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import junit.framework.Test;
import org.apache.commons.collections4.BulkTest;
import org.apache.commons.collections4.IterableMap;
import org.apache.commons.collections4.MapIterator;
import org.apache.commons.collections4.iterators.AbstractMapIteratorTest;
import junit.framework.Test;
/**
* JUnit tests.
*
@ -336,6 +336,29 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
assertEquals("NewValue", map.get(THREE));
}
public void testEntrySet() {
// Sanity check
putAndRemove(new HashMap<>());
// Actual test
putAndRemove(new Flat3Map<>());
}
private void putAndRemove(final Map<K, V> map) {
map.put((K) "A", (V) "one");
map.put((K) "B", (V) "two");
map.put((K) "C", (V) "three");
Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
Map.Entry<K, V> mapEntry1 = it.next();
Map.Entry<K, V> mapEntry2 = it.next();
Map.Entry<K, V> mapEntry3 = it.next();
it.remove();
assertEquals(2, map.size());
assertEquals("one", map.get((K) "A"));
assertEquals("two", map.get((K) "B"));
assertEquals(null, map.get((K) "C"));
}
//-----------------------------------------------------------------------
@Override
public BulkTest bulkTestMapIterator() {