Minor fix to avoid ConcurrentModificationException in policy-models 73/102073/2
authora.sreekumar <ajith.sreekumar@est.tech>
Thu, 20 Feb 2020 11:58:45 +0000 (11:58 +0000)
committera.sreekumar <ajith.sreekumar@est.tech>
Thu, 20 Feb 2020 13:12:18 +0000 (13:12 +0000)
Change-Id: If737f6ae0bcb0f8c694711a67a3c879fee8c11c5
Issue-ID: POLICY-1402
Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java

index 77633bd..88591bd 100644 (file)
 package org.onap.policy.models.tosca.utils;
 
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.Set;
 import java.util.function.Function;
-
 import javax.ws.rs.core.Response;
-
 import lombok.NonNull;
-
 import org.apache.commons.collections4.CollectionUtils;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfConceptContainer;
@@ -263,9 +261,11 @@ public final class ToscaUtils {
 
         @SuppressWarnings("unchecked")
         Set<JpaToscaEntityType<?>> filteredEntitySet =
-                (Set<JpaToscaEntityType<?>>) entityTypes.getAll(entityName, entityVersion);
+            (Set<JpaToscaEntityType<?>>) entityTypes.getAll(entityName, entityVersion);
+        Set<JpaToscaEntityType<?>> filteredEntitySetToReturn = new HashSet<>(filteredEntitySet);
         for (JpaToscaEntityType<?> filteredEntityType : filteredEntitySet) {
-            filteredEntitySet.addAll(ToscaUtils.getEntityTypeAncestors(entityTypes, filteredEntityType, result));
+            filteredEntitySetToReturn
+                .addAll(ToscaUtils.getEntityTypeAncestors(entityTypes, filteredEntityType, result));
         }
 
         if (!result.isValid()) {
@@ -273,6 +273,6 @@ public final class ToscaUtils {
         }
 
         entityTypes.getConceptMap().entrySet()
-                .removeIf(entityEntry -> !filteredEntitySet.contains(entityEntry.getValue()));
+                .removeIf(entityEntry -> !filteredEntitySetToReturn.contains(entityEntry.getValue()));
     }
 }