ONOS-3567 Protecting against NPE in MapValue isNewerThan
Change-Id: I8f2a46956a34d4bf50cb5b116d1c4001917daf1d
Showing
1 changed file
with
7 additions
and
2 deletions
... | @@ -20,6 +20,8 @@ import org.onosproject.store.Timestamp; | ... | @@ -20,6 +20,8 @@ import org.onosproject.store.Timestamp; |
20 | import com.google.common.base.MoreObjects; | 20 | import com.google.common.base.MoreObjects; |
21 | import com.google.common.base.Objects; | 21 | import com.google.common.base.Objects; |
22 | 22 | ||
23 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
24 | + | ||
23 | /** | 25 | /** |
24 | * Representation of a value in EventuallyConsistentMap. | 26 | * Representation of a value in EventuallyConsistentMap. |
25 | * | 27 | * |
... | @@ -42,7 +44,7 @@ public class MapValue<V> implements Comparable<MapValue<V>> { | ... | @@ -42,7 +44,7 @@ public class MapValue<V> implements Comparable<MapValue<V>> { |
42 | 44 | ||
43 | public MapValue(V value, Timestamp timestamp) { | 45 | public MapValue(V value, Timestamp timestamp) { |
44 | this.value = value; | 46 | this.value = value; |
45 | - this.timestamp = timestamp; | 47 | + this.timestamp = checkNotNull(timestamp, "Timestamp cannot be null"); |
46 | } | 48 | } |
47 | 49 | ||
48 | public boolean isTombstone() { | 50 | public boolean isTombstone() { |
... | @@ -67,7 +69,10 @@ public class MapValue<V> implements Comparable<MapValue<V>> { | ... | @@ -67,7 +69,10 @@ public class MapValue<V> implements Comparable<MapValue<V>> { |
67 | } | 69 | } |
68 | 70 | ||
69 | public boolean isNewerThan(MapValue<V> other) { | 71 | public boolean isNewerThan(MapValue<V> other) { |
70 | - return timestamp.isNewerThan(other.timestamp); | 72 | + if (other == null) { |
73 | + return true; | ||
74 | + } | ||
75 | + return this.timestamp.isNewerThan(other.timestamp); | ||
71 | } | 76 | } |
72 | 77 | ||
73 | public boolean isNewerThan(Timestamp timestamp) { | 78 | public boolean isNewerThan(Timestamp timestamp) { | ... | ... |
-
Please register or login to post a comment