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 e572c5444 Fix AbstractDualBidiMap.MapEntry.setValue returning new 
value (#711)
e572c5444 is described below

commit e572c54441e9ab72ebd53ddef1e744be071ec6a7
Author: Naveed Khan <[email protected]>
AuthorDate: Mon Jul 13 16:10:00 2026 +0000

    Fix AbstractDualBidiMap.MapEntry.setValue returning new value (#711)
---
 src/changes/changes.xml                                     |  1 +
 .../commons/collections4/bidimap/AbstractDualBidiMap.java   |  5 +++--
 .../commons/collections4/bidimap/AbstractBidiMapTest.java   | 13 +++++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f1663f196..3b760321a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,6 +24,7 @@
   <body>
   <release version="4.6.0" date="YYYY-MM-DD" description="This is a feature 
and maintenance release. Java 8 or later is required.">
     <!-- FIX -->
+    <action type="fix" dev="ggregory" due-to="Naveed Khan, Gary 
Gregory">DualHashBidiMap, DualLinkedHashBidiMap, and DualTreeBidiMap entrySet() 
Map.Entry.setValue(Object) returns the new value instead of the previous 
value.</action>
     <action type="fix" dev="ggregory" due-to="Naveed Khan, Gary 
Gregory">AbstractMapBag and AbstractMapMultiSet.add(Object, int) overflow the 
size and element count past Integer.MAX_VALUE.</action>
     <action type="fix" dev="ggregory" due-to="Naveed 
Khan">CompositeCollection, CompositeSet, CompositeMap, AbstractMultiValuedMap 
and AbstractMultiSet size() overflow int when the total exceeds 
Integer.MAX_VALUE.</action>
     <action type="fix" dev="ggregory" due-to="Gary Gregory" 
issue="COLLECTIONS-776">Wrapping PassiveExpiringMap in 
Collections.synchronizedMap breaks expiration.</action>
diff --git 
a/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java
 
b/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java
index 5fb336e20..b7d6a2532 100644
--- 
a/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java
+++ 
b/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java
@@ -359,8 +359,9 @@ public abstract class AbstractDualBidiMap<K, V> implements 
BidiMap<K, V> {
                 throw new IllegalArgumentException(
                         "Cannot use setValue() when the object being set is 
already in the map");
             }
-            parent.put(key, value);
-            return super.setValue(value);
+            final V oldValue = parent.put(key, value);
+            super.setValue(value);
+            return oldValue;
         }
     }
 
diff --git 
a/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java
 
b/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java
index 509723fef..aefafb3b0 100644
--- 
a/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java
+++ 
b/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java
@@ -108,6 +108,19 @@ public abstract class AbstractBidiMapTest<K, V> extends 
AbstractIterableMapTest<
             }
         }
 
+        @Test
+        void testMapEntrySetValueReturnsOldValue() {
+            if (!isSetValueSupported()) {
+                return;
+            }
+            final V newValue = getNewSampleValues()[0];
+            resetFull();
+            final Map.Entry<K, V> entry = 
BidiMapEntrySetTest.this.getCollection().iterator().next();
+            final V oldValue = entry.getValue();
+            assertEquals(oldValue, entry.setValue(newValue));
+            assertEquals(newValue, entry.getValue());
+        }
+
     }
 
     @Nested

Reply via email to