Fix for ONOS-393 - NPE when one of the devices can no longer be found

Change-Id: I5c907d8124585f9af5b3f6e7315c41cbcdd03fb9
diff --git a/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java b/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java
index be15bfc..be84a8b 100644
--- a/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java
+++ b/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java
@@ -29,6 +29,7 @@
 import org.onosproject.event.AbstractListenerRegistry;
 import org.onosproject.event.EventDeliveryService;
 import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Device;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.Link;
 import org.onosproject.net.Link.State;
@@ -273,9 +274,12 @@
     // Removes all links in the specified set and emits appropriate events.
     private void  removeLinks(Set<Link> links, boolean isSoftRemove) {
         for (Link link : links) {
-            if (!deviceService.getDevice(link.src().deviceId()).type().equals(
-                    deviceService.getDevice(link.dst().deviceId()).type())) {
-                //TODO this is aweful. need to be fixed so that we don't down
+            final Device srcDevice = deviceService.getDevice(link.src().deviceId());
+            final Device dstDevice = deviceService.getDevice(link.dst().deviceId());
+            if (srcDevice != null &&
+                    dstDevice != null &&
+                    !srcDevice.type().equals(dstDevice.type())) {
+                //TODO this is awful. need to be fixed so that we don't down
                 // configured links. perhaps add a mechanism to figure out the
                 // state of this link
                 log.info("Ignoring removal of link as device types are " +