Fixing NPE that can arise due to invalid host configuration.
Prevents NetworkConfigHostProvider from aborted activation.
Change-Id: I746cded81f8b264a6010475ab4b44a3010e69796
diff --git a/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java b/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java
index 42278d3..0588bde 100644
--- a/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java
+++ b/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java
@@ -152,10 +152,16 @@
BasicHostConfig hostConfig =
networkConfigRegistry.getConfig(hostId, BasicHostConfig.class);
Set<IpAddress> ipAddresses = hostConfig.ipAddresses();
- Set<HostLocation> locations = hostConfig.locations().stream()
- .map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis()))
- .collect(Collectors.toSet());
- addHost(mac, vlan, locations, ipAddresses);
+
+ Set<HostLocation> locs = hostConfig.locations();
+ if (locs != null) {
+ Set<HostLocation> locations = locs.stream()
+ .map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis()))
+ .collect(Collectors.toSet());
+ addHost(mac, vlan, locations, ipAddresses);
+ } else {
+ log.warn("Host {} configuration {} is missing locations", hostId, hostConfig);
+ }
});
}