Committed by
Gerrit Code Review
Bug fix: Removing an non-existing key from map should be a noop
Change-Id: I1a89327ab6b0a498fe403f17cbdb8783c41954a6
Showing
1 changed file
with
5 additions
and
1 deletions
... | @@ -151,10 +151,14 @@ public class DefaultDatabaseState implements DatabaseState<String, byte[]> { | ... | @@ -151,10 +151,14 @@ public class DefaultDatabaseState implements DatabaseState<String, byte[]> { |
151 | !versionMatch.matches(currentValue == null ? null : currentValue.version())) { | 151 | !versionMatch.matches(currentValue == null ? null : currentValue.version())) { |
152 | return Result.ok(new UpdateResult<>(false, mapName, key, currentValue, currentValue)); | 152 | return Result.ok(new UpdateResult<>(false, mapName, key, currentValue, currentValue)); |
153 | } else { | 153 | } else { |
154 | - if (value == null && currentValue != null) { | 154 | + if (value == null) { |
155 | + if (currentValue == null) { | ||
156 | + return Result.ok(new UpdateResult<>(false, mapName, key, null, null)); | ||
157 | + } else { | ||
155 | getMap(mapName).remove(key); | 158 | getMap(mapName).remove(key); |
156 | return Result.ok(new UpdateResult<>(true, mapName, key, currentValue, null)); | 159 | return Result.ok(new UpdateResult<>(true, mapName, key, currentValue, null)); |
157 | } | 160 | } |
161 | + } | ||
158 | Versioned<byte[]> newValue = new Versioned<>(value, ++nextVersion); | 162 | Versioned<byte[]> newValue = new Versioned<>(value, ++nextVersion); |
159 | getMap(mapName).put(key, newValue); | 163 | getMap(mapName).put(key, newValue); |
160 | return Result.ok(new UpdateResult<>(true, mapName, key, currentValue, newValue)); | 164 | return Result.ok(new UpdateResult<>(true, mapName, key, currentValue, newValue)); | ... | ... |
-
Please register or login to post a comment