[COLLECTIONS-445] Several workarounds for IBM JDKs flawed TreeMap.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1453585 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2013-03-06 21:57:53 +00:00
parent 88ca4cdf88
commit d5d29b625f
2 changed files with 14 additions and 2 deletions

View File

@ -362,7 +362,11 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
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() {

View File

@ -1921,7 +1921,8 @@ public abstract class AbstractMapTest<K, V> 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<K, V> extends AbstractObjectTest {
public void verifyValues() {
final List<V> known = new ArrayList<V>(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<V> test = new ArrayList<V>(values);
final int size = getConfirmed().size();