This is an automated email from the ASF dual-hosted git repository.

garydgregory 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 88d8b2f61 Reject remove on the Unmodifiable map from 
SplitMapUtils.readableMap (#718)
88d8b2f61 is described below

commit 88d8b2f618ea46872ed01a839259a3ef3f7f31e6
Author: Naveed Khan <[email protected]>
AuthorDate: Wed Jul 29 13:30:49 2026 +0000

    Reject remove on the Unmodifiable map from SplitMapUtils.readableMap (#718)
    
    * reject remove on the Unmodifiable map from SplitMapUtils.readableMap
    
    WrappedGet blocks clear, put and putAll and wraps every view it returns, 
but remove(Object) delegated to the wrapped Get, so the Unmodifiable view 
deleted from the underlying map. The Map default methods that route through 
remove inherited the hole.
    
    * address review: reword remove javadoc, cover compute in the test
---
 .../org/apache/commons/collections4/SplitMapUtils.java  |  8 +++++++-
 .../apache/commons/collections4/SplitMapUtilsTest.java  | 17 ++++++++++-------
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/commons/collections4/SplitMapUtils.java 
b/src/main/java/org/apache/commons/collections4/SplitMapUtils.java
index ea8a904d9..27d3e8a23 100644
--- a/src/main/java/org/apache/commons/collections4/SplitMapUtils.java
+++ b/src/main/java/org/apache/commons/collections4/SplitMapUtils.java
@@ -131,9 +131,15 @@ public class SplitMapUtils {
             throw new UnsupportedOperationException();
         }
 
+        /**
+         * Always throws {@link UnsupportedOperationException}.
+         *
+         * @param key The key whose mapping would be removed.
+         * @throws UnsupportedOperationException Always thrown.
+         */
         @Override
         public V remove(final Object key) {
-            return get.remove(key);
+            throw new UnsupportedOperationException();
         }
 
         @Override
diff --git 
a/src/test/java/org/apache/commons/collections4/SplitMapUtilsTest.java 
b/src/test/java/org/apache/commons/collections4/SplitMapUtilsTest.java
index 94628d0a2..a7226fc5b 100644
--- a/src/test/java/org/apache/commons/collections4/SplitMapUtilsTest.java
+++ b/src/test/java/org/apache/commons/collections4/SplitMapUtilsTest.java
@@ -97,7 +97,7 @@ class SplitMapUtilsTest {
         assertInstanceOf(Unmodifiable.class, map);
 
         // check individual operations
-        int sz = map.size();
+        final int sz = map.size();
 
         attemptPutOperation(map::clear);
 
@@ -116,12 +116,15 @@ class SplitMapUtilsTest {
         assertEquals(other, map);
         assertEquals(other.hashCode(), map.hashCode());
 
-        // remove
-        for (int i = 0; i < 10; i++) {
-            assertEquals(i, map.remove(String.valueOf(i)).intValue());
-            assertEquals(--sz, map.size());
-        }
-        assertTrue(map.isEmpty());
+        // remove, and the Map default methods that route through it
+        attemptPutOperation(() -> map.remove("0"));
+        attemptPutOperation(() -> map.remove("1", 1));
+        attemptPutOperation(() -> map.computeIfPresent("2", (k, v) -> null));
+        attemptPutOperation(() -> map.compute("3", (k, v) -> null));
+        attemptPutOperation(() -> map.merge("4", 4, (a, b) -> null));
+
+        assertEquals(sz, map.size());
+        assertEquals(sz, backingMap.size());
         assertSame(map, SplitMapUtils.readableMap(map));
     }
 

Reply via email to