Fix NPE 96/116696/7
authorJan Malkiewicz <jan.malkiewicz@nokia.com>
Fri, 8 Jan 2021 13:28:15 +0000 (14:28 +0100)
committerVasyl Razinkov <vasyl.razinkov@est.tech>
Mon, 11 Jan 2021 10:25:30 +0000 (10:25 +0000)
Fix NPE during the onboarding of a helm package.
NPE was thrown in HeatTreeManager.handleOrphans():
 *  tree.getHeat()::contains

Issue-ID: SDC-3185
Signed-off-by: Jan Malkiewicz <jan.malkiewicz@nokia.com>
Change-Id: I9e0461cfe18705b6fb53ae318e473bd4e2651305

openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/HeatTreeManagerTest.java
openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/structure/HeatStructureTree.java
openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerTest.java
openecomp-be/lib/openecomp-heat-lib/src/test/resources/mock/toscaTree/diffFileNames/out/expectedTree.json
openecomp-be/lib/openecomp-heat-lib/src/test/resources/mock/toscaTree/similarDirectoryName/out/expectedTree.json
openecomp-be/lib/openecomp-heat-lib/src/test/resources/mock/toscaTree/twoFilesUnderSameDirectory/out/expectedTree.json

index 6b1493f..14eba87 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2016-2018 European Support Limited
+ * Modifications Copyright (C) 2021 Nokia
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -67,7 +68,7 @@ public class HeatTreeManagerTest extends TreeBaseTest {
     heatTreeManager.addErrors(errorMap);
     HeatStructureTree tree = heatTreeManager.getTree();
     Assert.assertNotNull(tree);
-    Assert.assertNull(tree.getHeat());
+    Assert.assertTrue(tree.getHeat().isEmpty());
 
   }
 
index a65db6f..93eb7c6 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright (C) 2021 Nokia
+ * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -24,7 +26,6 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
-
 import lombok.AccessLevel;
 import lombok.Data;
 import lombok.Getter;
@@ -53,9 +54,11 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> {
     private Set<HeatStructureTree> helm;
 
     public HeatStructureTree() {
+        heat = new TreeSet<>();
     }
 
     public HeatStructureTree(String fileName, boolean isBase) {
+        this();
         this.isBase = isBase;
         this.fileName = fileName;
     }
@@ -76,7 +79,7 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> {
      * @return the heat structure tree by name
      */
     public static HeatStructureTree getHeatStructureTreeByName(Set<HeatStructureTree> filesSet,
-                                                               String filename) {
+        String filename) {
         for (HeatStructureTree heatStructureTree : filesSet) {
             if (heatStructureTree.getFileName().equals(filename)) {
                 return heatStructureTree;
@@ -166,7 +169,7 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> {
         this.other.add(other);
     }
 
-    public void addToHelmList(HeatStructureTree helm){
+    public void addToHelmList(HeatStructureTree helm) {
         if (this.helm == null) {
             this.helm = new TreeSet<>();
         }
@@ -198,7 +201,7 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> {
      */
     public void removeFromVolumeOrNetwork(String fileNameToRemove, FileData.Type type) {
         Set<HeatStructureTree> volumeOrNetworkSet =
-                type.equals(FileData.Type.HEAT_VOL) ? this.volume : this.network;
+            type.equals(FileData.Type.HEAT_VOL) ? this.volume : this.network;
         HeatStructureTree toRemove = getHeatStructureTreeByName(volumeOrNetworkSet, fileNameToRemove);
 
         volumeOrNetworkSet.remove(toRemove);
@@ -215,7 +218,6 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> {
         result1 = 31 * result1 + (nested != null ? nested.hashCode() : 0);
         result1 = 31 * result1 + (errors != null ? errors.hashCode() : 0);
 
-
         return result1;
     }
 
@@ -231,7 +233,7 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> {
         HeatStructureTree heatStructureTree = (HeatStructureTree) other;
 
         if (fileName != null ? !fileName.equals(heatStructureTree.fileName)
-                : heatStructureTree.fileName != null) {
+            : heatStructureTree.fileName != null) {
             return false;
         }
         if (env != null ? !env.equals(heatStructureTree.env) : heatStructureTree.env != null) {
@@ -241,19 +243,19 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> {
             return false;
         }
         if (volume != null ? !volume.equals(heatStructureTree.volume)
-                : heatStructureTree.volume != null) {
+            : heatStructureTree.volume != null) {
             return false;
         }
         if (network != null ? !network.equals(heatStructureTree.network)
-                : heatStructureTree.network != null) {
+            : heatStructureTree.network != null) {
             return false;
         }
         if (artifacts != null ? !artifacts.equals(heatStructureTree.artifacts)
-                : heatStructureTree.artifacts != null) {
+            : heatStructureTree.artifacts != null) {
             return false;
         }
         if (nested != null ? !nested.equals(heatStructureTree.nested)
-                : heatStructureTree.nested != null) {
+            : heatStructureTree.nested != null) {
             return false;
         }
 
index e3e1979..0ff4bdd 100644 (file)
@@ -1,6 +1,7 @@
 /*
  *
  *  Copyright © 2017-2018 European Support Limited
+ *  Modifications Copyright (C) 2021 Nokia
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
index 4be1e1d..de60261 100644 (file)
@@ -1,23 +1,29 @@
 {
+  "heat": [],
   "nested": [
     {
       "fileName": "TOSCA-Metadata",
+      "heat": [],
       "nested": [
         {
-          "fileName": "TOSCA.meta"
+          "fileName": "TOSCA.meta",
+          "heat": []
         }
       ]
     },
     {
-      "fileName": "MainServiceTemplate.yaml"
+      "fileName": "MainServiceTemplate.yaml",
+      "heat": []
     },
     {
       "fileName": "Definitions",
+      "heat": [],
       "nested": [
         {
-          "fileName": "GlobalSubstitutionTypesServiceTemplate.yaml"
+          "fileName": "GlobalSubstitutionTypesServiceTemplate.yaml",
+          "heat": []
         }
       ]
     }
   ]
-}
\ No newline at end of file
+}
index 071887b..c6e5cde 100644 (file)
@@ -1,43 +1,55 @@
 {
+  "heat": [],
   "nested": [
     {
       "fileName": "TOSCA-Metadata",
+      "heat": [],
       "nested": [
         {
-          "fileName": "TOSCA.meta"
+          "fileName": "TOSCA.meta",
+          "heat": []
         }
       ]
     },
     {
-      "fileName": "MainServiceTemplate.yaml"
+      "fileName": "MainServiceTemplate.yaml",
+      "heat": []
     },
     {
       "fileName": "Definitions",
+      "heat": [],
       "nested": [
         {
-          "fileName": "GlobalSubstitutionTypesServiceTemplate.yaml"
+          "fileName": "GlobalSubstitutionTypesServiceTemplate.yaml",
+          "heat": []
         }
       ]
     },
     {
       "fileName": "Artifacts",
+      "heat": [],
       "nested": [
         {
           "fileName": "OTHER",
+          "heat": [],
           "nested": [
             {
-              "fileName": "clearWaterIMSOTHER.zip"
+              "fileName": "clearWaterIMSOTHER.zip",
+              "heat": []
             }
           ]
         },
         {
           "fileName": "Deployment",
+          "heat": [],
           "nested": [
             {
               "fileName": "OTHER",
+              "heat": [],
               "nested": [
                 {
-                  "fileName": "clearWaterIMSOTHERDEPLOYMENT.zip"
+                  "fileName": "clearWaterIMSOTHERDEPLOYMENT.zip",
+                  "heat": []
                 }
               ]
             }
@@ -46,4 +58,4 @@
       ]
     }
   ]
-}
\ No newline at end of file
+}
index 59fec70..c73b6b9 100644 (file)
@@ -1,39 +1,49 @@
 {
+  "heat": [],
   "nested": [
     {
       "fileName": "TOSCA-Metadata",
+      "heat": [],
       "nested": [
         {
-          "fileName": "TOSCA.meta"
+          "fileName": "TOSCA.meta",
+          "heat": []
         }
       ]
     },
     {
-      "fileName": "MainServiceTemplate.yaml"
+      "fileName": "MainServiceTemplate.yaml",
+      "heat": []
     },
     {
       "fileName": "Definitions",
+      "heat": [],
       "nested": [
         {
-          "fileName": "GlobalSubstitutionTypesServiceTemplate.yaml"
+          "fileName": "GlobalSubstitutionTypesServiceTemplate.yaml",
+          "heat": []
         }
       ]
     },
     {
       "fileName": "Artifacts",
+      "heat": [],
       "nested": [
         {
           "fileName": "OTHER",
+          "heat": [],
           "nested": [
             {
-              "fileName": "clearWaterIMSOTHERDEPLOYMENT.zip"
+              "fileName": "clearWaterIMSOTHERDEPLOYMENT.zip",
+              "heat": []
             },
             {
-              "fileName": "clearWaterIMSOTHER.zip"
+              "fileName": "clearWaterIMSOTHER.zip",
+              "heat": []
             }
           ]
         }
       ]
     }
   ]
-}
\ No newline at end of file
+}