Madan Jampani
Committed by Gerrit Code Review

Bug fix: Removing an non-existing key from map should be a noop

Change-Id: I1a89327ab6b0a498fe403f17cbdb8783c41954a6
......@@ -151,10 +151,14 @@ public class DefaultDatabaseState implements DatabaseState<String, byte[]> {
!versionMatch.matches(currentValue == null ? null : currentValue.version())) {
return Result.ok(new UpdateResult<>(false, mapName, key, currentValue, currentValue));
} else {
if (value == null && currentValue != null) {
if (value == null) {
if (currentValue == null) {
return Result.ok(new UpdateResult<>(false, mapName, key, null, null));
} else {
getMap(mapName).remove(key);
return Result.ok(new UpdateResult<>(true, mapName, key, currentValue, null));
}
}
Versioned<byte[]> newValue = new Versioned<>(value, ++nextVersion);
getMap(mapName).put(key, newValue);
return Result.ok(new UpdateResult<>(true, mapName, key, currentValue, newValue));
......