Project: Eclipse_Platform_UI
Bug 184817 [DataBinding] WritableMap.put(...) fires an incorrect event
Reported: 2007-04-30 21:51:05 | Status: verified fixed

The event for WritableMap.put(...) when the key already exists reverses the new and old values in the change event. The following test will fail on the old value as it will be the new value. public void testPutWithExistingKeyMapChangeEvent() throws Exception { WritableMap map = new WritableMap(); String key = "key"; String value = "value"; map.put(key, value); MapChangeEventTracker listener = new MapChangeEventTracker(); map.addMapChangeListener(listener); assertEquals(0, listener.count); String newValue = "new value"; map.put(key, newValue); assertEquals(1, listener.count); MapChangeEvent event = listener.event; Set changedKeys = event.diff.getChangedKeys(); assertEquals(1, changedKeys.size()); assertTrue(changedKeys.contains(key)); assertEquals(value, event.diff.getOldValue(key)); //<<<FAILS assertEquals(newValue, event.diff.getNewValue(key)); }

Files changed in fix:
bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/WritableMap.java bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/WritableMap.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/map/WritableMapTest.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/EventTrackers.java