From: Ankit Jain Date: Fri, 7 Sep 2018 06:55:01 +0000 (+0530) Subject: Fixes for few NullPointerException X-Git-Tag: release/neon~145 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=97648a8357c5fb17fa49e67d17ae2595ed95716d;p=netvirt.git Fixes for few NullPointerException Change-Id: I9164090262bb702607e90a9e53298f295120cd91 Signed-off-by: Ankit Jain --- diff --git a/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpPktHandler.java b/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpPktHandler.java index 10934c49b9..1c4c2b007f 100644 --- a/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpPktHandler.java +++ b/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpPktHandler.java @@ -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 dnsServers = subnet.getDnsNameservers(); + List 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 subnetHostRoutes = new ArrayList<>(subnet.getHostRoutes().size()); - for (HostRoutes hostRoute : subnet.getHostRoutes()) { - if (!hostRoute.getNexthop().stringValue().equals(clientIp)) { - subnetHostRoutes.add(hostRoute); + List 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> 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) {