commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject [commons-collections] branch master updated: [COLLECTIONS-734] Encountered an IllegalStateException while traversing with Flat3Map.entrySet().
Date Thu, 05 Dec 2019 16:12:49 GMT
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git


The following commit(s) were added to refs/heads/master by this push:
     new 45b6865  [COLLECTIONS-734] Encountered an IllegalStateException while traversing
with Flat3Map.entrySet().
45b6865 is described below

commit 45b6865b59d344910dd8cf09b54e6ea91347752d
Author: Gary Gregory <garydgregory@gmail.com>
AuthorDate: Thu Dec 5 11:12:44 2019 -0500

    [COLLECTIONS-734] Encountered an IllegalStateException while traversing
    with Flat3Map.entrySet().
    
    Closes #115. This is slightly modified patch from the PR.
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    .
---
 src/changes/changes.xml                            |  3 +++
 .../apache/commons/collections4/map/Flat3Map.java  |  2 +-
 .../commons/collections4/map/Flat3MapTest.java     | 27 ++++++++++++++++++++--
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b84478e..fb6b285 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -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">
diff --git a/src/main/java/org/apache/commons/collections4/map/Flat3Map.java b/src/main/java/org/apache/commons/collections4/map/Flat3Map.java
index 2bfa20a..c506c53 100644
--- a/src/main/java/org/apache/commons/collections4/map/Flat3Map.java
+++ b/src/main/java/org/apache/commons/collections4/map/Flat3Map.java
@@ -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;
         }
diff --git a/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java b/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java
index c234349..d4e3b29 100644
--- a/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java
@@ -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() {


Mime
View raw message