Fixes for few NullPointerException 25/75825/5
authorAnkit Jain <ankit.j.jain@ericsson.com>
Fri, 7 Sep 2018 06:55:01 +0000 (12:25 +0530)
committerSam Hague <shague@redhat.com>
Mon, 17 Sep 2018 00:13:25 +0000 (00:13 +0000)
Change-Id: I9164090262bb702607e90a9e53298f295120cd91
Signed-off-by: Ankit Jain <ankit.j.jain@ericsson.com>
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpPktHandler.java

index 10934c49b922a505bd2164bcf17b6d407a9ec2d7..1c4c2b007f212bc14fcf2c0cd1a18e42a24d611b 100644 (file)
@@ -192,6 +192,7 @@ public class DhcpPktHandler implements PacketProcessingListener {
                 if (interfaceName == null) {
                     pktDropCounter.label(macAddress).label(UNKNOWN_LABEL).label(
                             PktDropReason.INTERFACE_NAME_NOT_FOUND.name()).increment();
+                    return;
                 }
                 InterfaceInfo interfaceInfo =
                         interfaceManager.getInterfaceInfoFromOperationalDataStore(interfaceName);
@@ -331,17 +332,22 @@ public class DhcpPktHandler implements PacketProcessingListener {
     private DhcpInfo getDhcpInfo(Port port, Subnet subnet, String serverIp) {
         DhcpInfo dhcpInfo = null;
         if (port != null && subnet != null) {
-            String clientIp = getIpv4Address(port);
-            List<IpAddress> dnsServers = subnet.getDnsNameservers();
+            List<IpAddress> dnsServers = new ArrayList<>();
+            if (subnet.getDnsNameservers() != null && !subnet.getDnsNameservers().isEmpty()) {
+                dnsServers = subnet.getDnsNameservers();
+            }
             dhcpInfo = new DhcpInfo();
             if (isIpv4Address(subnet.getGatewayIp())) {
                 dhcpInfo.setGatewayIp(subnet.getGatewayIp().getIpv4Address().getValue());
             }
+            String clientIp = getIpv4Address(port);
             if (clientIp != null && serverIp != null) {
-                List<HostRoutes> subnetHostRoutes = new ArrayList<>(subnet.getHostRoutes().size());
-                for (HostRoutes hostRoute : subnet.getHostRoutes()) {
-                    if (!hostRoute.getNexthop().stringValue().equals(clientIp)) {
-                        subnetHostRoutes.add(hostRoute);
+                List<HostRoutes> subnetHostRoutes = new ArrayList<>();
+                if (subnet.getHostRoutes() != null && !subnet.getHostRoutes().isEmpty()) {
+                    for (HostRoutes hostRoute : subnet.getHostRoutes()) {
+                        if (!hostRoute.getNexthop().stringValue().equals(clientIp)) {
+                            subnetHostRoutes.add(hostRoute);
+                        }
                     }
                 }
                 dhcpInfo.setClientIp(clientIp).setServerIp(serverIp)
@@ -777,6 +783,10 @@ public class DhcpPktHandler implements PacketProcessingListener {
         Future<RpcResult<GetInterfaceFromIfIndexOutput>> futureOutput =
                 interfaceManagerRpc.getInterfaceFromIfIndex(input);
         try {
+            if (!futureOutput.get().isSuccessful()) {
+                LOG.error("Failed to get the interface name from tag {} using getInterfaceFromIfIndex RPC", portTag);
+                return null;
+            }
             GetInterfaceFromIfIndexOutput output = futureOutput.get().getResult();
             interfaceName = output.getInterfaceName();
         } catch (InterruptedException | ExecutionException e) {