From fb3a2ecb57e5c9c0256a3251da613cf1f950ca33 Mon Sep 17 00:00:00 2001 From: Harikrishna Date: Thu, 12 Oct 2023 00:25:34 +0530 Subject: [PATCH] Fix NPE if global setting implicit.host.tags is set to null (#8066) --- .../main/java/com/cloud/deploy/FirstFitPlanner.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/com/cloud/deploy/FirstFitPlanner.java b/server/src/main/java/com/cloud/deploy/FirstFitPlanner.java index 695521e5272..4e838510010 100644 --- a/server/src/main/java/com/cloud/deploy/FirstFitPlanner.java +++ b/server/src/main/java/com/cloud/deploy/FirstFitPlanner.java @@ -124,7 +124,7 @@ public class FirstFitPlanner extends AdapterBase implements DeploymentClusterPla protected String allocationAlgorithm = "random"; protected String globalDeploymentPlanner = "FirstFitPlanner"; - protected String[] implicitHostTags; + protected String[] implicitHostTags = new String[0]; @Override public List orderClusters(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException { @@ -214,11 +214,11 @@ public class FirstFitPlanner extends AdapterBase implements DeploymentClusterPla Long uniqueTags; for (Long clusterId : clusterList) { uniqueTags = (long) 0; - List hostList = capacityDao.listHostsWithEnoughCapacity(requiredCpu, requiredRam, clusterId, Host.Type.Routing.toString()); - if (!hostList.isEmpty() && implicitHostTags.length > 0) { - uniqueTags = new Long(hostTagsDao.getDistinctImplicitHostTags(hostList, implicitHostTags).size()); - uniqueTags = uniqueTags + getHostsByCapability(hostList, Host.HOST_UEFI_ENABLE); - } + List hostList = capacityDao.listHostsWithEnoughCapacity(requiredCpu, requiredRam, clusterId, Host.Type.Routing.toString()); + if (!hostList.isEmpty() && implicitHostTags.length > 0) { + uniqueTags = new Long(hostTagsDao.getDistinctImplicitHostTags(hostList, implicitHostTags).size()); + uniqueTags = uniqueTags + getHostsByCapability(hostList, Host.HOST_UEFI_ENABLE); + } UniqueTagsInClusterMap.put(clusterId, uniqueTags); } Collections.sort(clusterList, new Comparator() {