diff --git a/src/main/java/org/apache/commons/collections/bidimap/DualTreeBidiMap.java b/src/main/java/org/apache/commons/collections/bidimap/DualTreeBidiMap.java index bb31766c7..f9a934951 100644 --- a/src/main/java/org/apache/commons/collections/bidimap/DualTreeBidiMap.java +++ b/src/main/java/org/apache/commons/collections/bidimap/DualTreeBidiMap.java @@ -362,7 +362,11 @@ public class DualTreeBidiMap extends AbstractDualBidiMap throw new IllegalArgumentException( "Cannot use setValue() when the object being set is already in the map"); } - return parent.put(last.getKey(), value); + final V oldValue = parent.put(last.getKey(), value); + // set also the value in the Map.Entry: + // due to a bug in IBM JDK where the Entry is not in sync with the underlying map + last.setValue(value); + return oldValue; } public void reset() { diff --git a/src/test/java/org/apache/commons/collections/map/AbstractMapTest.java b/src/test/java/org/apache/commons/collections/map/AbstractMapTest.java index aa48640ee..914f6c442 100644 --- a/src/test/java/org/apache/commons/collections/map/AbstractMapTest.java +++ b/src/test/java/org/apache/commons/collections/map/AbstractMapTest.java @@ -1921,7 +1921,8 @@ public abstract class AbstractMapTest extends AbstractObjectTest { */ private void views() { this.keySet = getMap().keySet(); - this.values = getMap().values(); + // see verifyValues: retrieve the values collection only when verifying them + // this.values = getMap().values(); this.entrySet = getMap().entrySet(); } @@ -1999,6 +2000,13 @@ public abstract class AbstractMapTest extends AbstractObjectTest { public void verifyValues() { final List known = new ArrayList(getConfirmed().values()); + + // bug in IBM JDK: IBM J9 VM build 2.4, JRE 1.6.0 IBM J9 2.4 Linux x86-32 jvmxi3260sr12-20121024_126067 + // a call to values() on an empty map retrieved via TreeMap#headMap or tailMap + // will render the values view unusable: resulting in NullPointExceptions or missing values + // it will also not recover, as the value view is cached internally + values = getMap().values(); + final List test = new ArrayList(values); final int size = getConfirmed().size();