Guard NPE in HeartbeatMonitor
fixes gh-129
This commit is contained in:
@@ -34,7 +34,7 @@ public class HeartbeatMonitor {
|
||||
*/
|
||||
public boolean update(Object value) {
|
||||
Object last = this.latestHeartbeat.get();
|
||||
if (!value.equals(last)) {
|
||||
if (value != null && !value.equals(last)) {
|
||||
return this.latestHeartbeat.compareAndSet(last, value);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -40,4 +40,15 @@ public class HeartbeatMonitorTests {
|
||||
assertTrue(this.monitor.update("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullInitialValue() {
|
||||
assertFalse(this.monitor.update(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullSecondValue() {
|
||||
assertTrue(this.monitor.update("foo"));
|
||||
assertFalse(this.monitor.update(null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user