Fix npe during hostVanished handling
java.lang.NullPointerException: null
at org.onosproject.net.host.impl.HostManager$InternalHostProviderService.hostVanished(HostManager.java:573) ~[?:?]
at org.onosproject.provider.netcfghost.NetworkConfigHostProvider.removeHost(NetworkConfigHostProvider.java:189) ~[?:?]
at org.onosproject.provider.netcfghost.NetworkConfigHostProvider$InternalNetworkConfigListener.event(NetworkConfigHostProvider.java:274) ~[?:?]
at org.onosproject.provider.netcfghost.NetworkConfigHostProvider$InternalNetworkConfigListener.event(NetworkConfigHostProvider.java:222) ~[?:?]
at org.onosproject.event.ListenerRegistry.process(ListenerRegistry.java:66) [!/:?]
at org.onosproject.event.impl.CoreEventDispatcher$DispatchLoop.process(CoreEventDispatcher.java:198) [!/:?]
at org.onosproject.event.impl.CoreEventDispatcher$DispatchLoop.run(CoreEventDispatcher.java:180) [!/:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:834) [?:?]
Change-Id: If6e3978798d5fb11b3f5b1344b551b9f3cd3e51d
(cherry picked from commit 3a615560678cb83fa41f393fa59c346cdae659e2)
diff --git a/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java b/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
index 46cbc0a..a02159c 100644
--- a/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
+++ b/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
@@ -562,6 +562,7 @@
public void hostVanished(HostId hostId) {
checkNotNull(hostId, HOST_ID_NULL);
checkValidity();
+ // TODO SDFAB-718 rethink HostStore APIs to allow atomic operations
Host host = store.getHost(hostId);
if (!allowedToChange(hostId)) {
@@ -569,6 +570,11 @@
return;
}
+ if (host == null) {
+ log.info("Request to remove {} is ignored due to host not present in the store", hostId);
+ return;
+ }
+
if (monitorHosts) {
host.ipAddresses().forEach(ip -> {
monitor.stopMonitoring(ip);