[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:
parent
f08623354e
commit
45b6865b59
|
@ -87,6 +87,9 @@
|
||||||
<action dev="ggregory" type="update" due-to="Gary Gregory">
|
<action dev="ggregory" type="update" due-to="Gary Gregory">
|
||||||
[test] org.easymock:easymock 4.0.2 -> 4.1.
|
[test] org.easymock:easymock 4.0.2 -> 4.1.
|
||||||
</action>
|
</action>
|
||||||
|
<action issue="COLLECTIONS-734" dev="ggregory" type="fix" due-to="Chen">
|
||||||
|
Encountered an IllegalStateException while traversing with Flat3Map.entrySet(). #115.
|
||||||
|
</action>
|
||||||
</release>
|
</release>
|
||||||
<release version="4.4" date="2019-07-05" description="Maintenance 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">
|
<action issue="COLLECTIONS-710" dev="ggregory" type="fix" due-to="Yu Shi, Gary Gregory">
|
||||||
|
|
|
@ -946,8 +946,8 @@ public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneabl
|
||||||
if (currentEntry == null) {
|
if (currentEntry == null) {
|
||||||
throw new IllegalStateException(AbstractHashedMap.REMOVE_INVALID);
|
throw new IllegalStateException(AbstractHashedMap.REMOVE_INVALID);
|
||||||
}
|
}
|
||||||
currentEntry.setRemoved(true);
|
|
||||||
parent.remove(currentEntry.getKey());
|
parent.remove(currentEntry.getKey());
|
||||||
|
currentEntry.setRemoved(true);
|
||||||
nextIndex--;
|
nextIndex--;
|
||||||
currentEntry = null;
|
currentEntry = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,13 @@ import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.apache.commons.collections4.BulkTest;
|
import org.apache.commons.collections4.BulkTest;
|
||||||
import org.apache.commons.collections4.IterableMap;
|
import org.apache.commons.collections4.IterableMap;
|
||||||
import org.apache.commons.collections4.MapIterator;
|
import org.apache.commons.collections4.MapIterator;
|
||||||
import org.apache.commons.collections4.iterators.AbstractMapIteratorTest;
|
import org.apache.commons.collections4.iterators.AbstractMapIteratorTest;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit tests.
|
* JUnit tests.
|
||||||
*
|
*
|
||||||
|
@ -336,6 +336,29 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
||||||
assertEquals("NewValue", map.get(THREE));
|
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
|
@Override
|
||||||
public BulkTest bulkTestMapIterator() {
|
public BulkTest bulkTestMapIterator() {
|
||||||
|
|
Loading…
Reference in New Issue