From fc752e96f324f9027a20e1b071167bf294202545 Mon Sep 17 00:00:00 2001 From: talio Date: Thu, 16 Aug 2018 10:49:35 +0300 Subject: Fix NPE Fix NPE in CompositionDataExtractor, by checking if a list is null before looping on it. Change-Id: I6441662684ad55d275626c8c813cb910ef5c00f7 Issue-ID: SDC-1513 Signed-off-by: talio --- .../composition/CompositionDataExtractorImpl.java | 29 ++++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'openecomp-be/lib') diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImpl.java index 33ad16c12d..aded0dfbae 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImpl.java @@ -330,24 +330,31 @@ public class CompositionDataExtractorImpl implements CompositionDataExtractor { List images = imageList.get(computeId); List computeFlavors = computeFlavorNodeTemplates.get(computeId); - if (connectedPortIds != null) { + if (CollectionUtils.isNotEmpty(connectedPortIds)) { componentModel.setNics(new ArrayList<>()); componentModel.setImages(new ArrayList<>()); componentModel.setCompute(new ArrayList<>()); - for (String portId : connectedPortIds) { + + connectedPortIds.forEach(portId -> { Nic port = extractPort(serviceTemplate, portId); componentModel.getNics().add(port); context.addNic(portId, port); + }); + + if (CollectionUtils.isNotEmpty(images)) { + images.forEach(image -> { + Image img = new Image(image); + componentModel.getImages().add(img); + context.addImage(image, img); + }); } - for (String image : images) { - Image img = new Image(image); - componentModel.getImages().add(img); - context.addImage(image, img); - } - for (String flavor : computeFlavors) { - ComputeData computeFlavor = new ComputeData(flavor); - componentModel.getCompute().add(computeFlavor); - context.addCompute(flavor,computeFlavor); + + if (CollectionUtils.isNotEmpty(computeFlavors)) { + computeFlavors.forEach(flavor -> { + ComputeData computeFlavor = new ComputeData(flavor); + componentModel.getCompute().add(computeFlavor); + context.addCompute(flavor, computeFlavor); + }); } } context.addComponent(componentModel); -- cgit 1.2.3-korg