Don't assume that there is a device id in the event message

Change-Id: Ibf77ea7c8fec1a7baff5fa6e0aca50bb7cb3425b
diff --git a/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java b/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
index 036ac0c..8ed8a57 100644
--- a/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
+++ b/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
@@ -1061,14 +1061,20 @@
     }
 
     private class InternalNetworkConfigListener implements NetworkConfigListener {
-        @Override
-        public boolean isRelevant(NetworkConfigEvent event) {
-            DeviceId deviceId;
+        private DeviceId extractDeviceId(NetworkConfigEvent event) {
+            DeviceId deviceId = null;
             if (event.configClass().equals(PortAnnotationConfig.class)) {
                 deviceId = ((ConnectPoint) event.subject()).deviceId();
-            } else {
+            } else if (event.subject().getClass() == DeviceId.class) {
                 deviceId = (DeviceId) event.subject();
             }
+            return deviceId;
+        }
+
+        @Override
+        public boolean isRelevant(NetworkConfigEvent event) {
+            DeviceId deviceId = extractDeviceId(event);
+
             return (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED
                     || event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED
                     || event.type() == NetworkConfigEvent.Type.CONFIG_REMOVED)
@@ -1076,7 +1082,7 @@
                     || portOpsIndex.containsKey(event.configClass())
                     || event.configClass().equals(PortDescriptionsConfig.class)
                     || event.configClass().equals(DeviceAnnotationConfig.class))
-                    && mastershipService.isLocalMaster(deviceId);
+                    && deviceId != null && mastershipService.isLocalMaster(deviceId);
         }
 
         @Override