Added null check for rootNode to prevent crash at 33/93933/2
authorOleksandr Moliavko <o.moliavko@samsung.com>
Tue, 20 Aug 2019 08:32:52 +0000 (11:32 +0300)
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>
Wed, 21 Aug 2019 13:23:55 +0000 (13:23 +0000)
for loop.

Issue-ID: SO-1841
Signed-off-by: Oleksandr Moliavko <o.moliavko@samsung.com>
Change-Id: I5ec16f3d73982c89e2bf5b14758274f1d4dd7740

adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java

index 153de2f..be4cc5a 100644 (file)
@@ -1521,23 +1521,28 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             logger.debug("Subnet_Ipam Output JSON String:{} {}", obj.getClass(), jStr);
 
             JsonNode rootNode = mapper.readTree(jStr);
-            for (JsonNode sNode : rootNode.path("ipam_subnets")) {
-                logger.debug("Output Subnet Node {}", sNode.toString());
-                String name = sNode.path("subnet_name").textValue();
-                String uuid = sNode.path("subnet_uuid").textValue();
-                String aaiId = name; // default
-                // try to find aaiId for name in input subnetList
-                if (subnets != null) {
-                    for (Subnet subnet : subnets) {
-                        if (subnet != null && !commonUtils.isNullOrEmpty(subnet.getSubnetName())) {
-                            if (subnet.getSubnetName().equals(name)) {
-                                aaiId = subnet.getSubnetId();
-                                break;
+            if (rootNode != null) {
+                for (JsonNode sNode : rootNode.path("ipam_subnets")) {
+                    logger.debug("Output Subnet Node {}", sNode.toString());
+                    String name = sNode.path("subnet_name").textValue();
+                    String uuid = sNode.path("subnet_uuid").textValue();
+                    String aaiId = name; // default
+                    // try to find aaiId for name in input subnetList
+                    if (subnets != null) {
+                        for (Subnet subnet : subnets) {
+                            if (subnet != null && !commonUtils.isNullOrEmpty(subnet.getSubnetName())) {
+                                if (subnet.getSubnetName().equals(name)) {
+                                    aaiId = subnet.getSubnetId();
+                                    break;
+                                }
                             }
                         }
                     }
+                    sMap.put(aaiId, uuid); // bpmn needs aaid to uuid map
                 }
-                sMap.put(aaiId, uuid); // bpmn needs aaid to uuid map
+            } else {
+                logger.error("{} {} null rootNode - cannot get subnet-uuids", MessageEnum.RA_MARSHING_ERROR,
+                        ErrorCode.DataError.getValue());
             }
         } catch (Exception e) {
             logger.error("{} {} Exception getting subnet-uuids ", MessageEnum.RA_MARSHING_ERROR,