Fix possible concurrency flaws in ArpHandler

Change-Id: I7e869453aefa580246af593c211aa98fb417f5cc
diff --git a/src/main/java/org/onosproject/segmentrouting/ArpHandler.java b/src/main/java/org/onosproject/segmentrouting/ArpHandler.java
index 6ca6d19..f42f84b 100644
--- a/src/main/java/org/onosproject/segmentrouting/ArpHandler.java
+++ b/src/main/java/org/onosproject/segmentrouting/ArpHandler.java
@@ -88,7 +88,6 @@
     }
 
     private void handleArpRequest(DeviceId deviceId, ConnectPoint inPort, Ethernet payload) {
-
         ARP arpRequest = (ARP) payload.getPayload();
         HostId targetHostId = HostId.hostId(MacAddress.valueOf(
                 arpRequest.getTargetHardwareAddress()));
@@ -98,14 +97,16 @@
             Ip4Address targetAddress = Ip4Address.valueOf(arpRequest.getTargetProtocolAddress());
 
             sendArpResponse(arpRequest, config.getRouterMacForAGatewayIp(targetAddress));
-        // ARP request for known hosts
-        } else if (srManager.hostService.getHost(targetHostId) != null) {
-            MacAddress targetMac = srManager.hostService.getHost(targetHostId).mac();
-            sendArpResponse(arpRequest, targetMac);
+        } else {
+            Host targetHost = srManager.hostService.getHost(targetHostId);
+            // ARP request for known hosts
+            if (targetHost != null) {
+                sendArpResponse(arpRequest, targetHost.mac());
 
-        // ARP request for unknown host in the subnet
-        } else if (isArpReqForSubnet(deviceId, arpRequest)) {
-            flood(payload, inPort);
+            // ARP request for unknown host in the subnet
+            } else if (isArpReqForSubnet(deviceId, arpRequest)) {
+                flood(payload, inPort);
+            }
         }
     }