From f6073052aa3d592d6d737990a95c44e702908d59 Mon Sep 17 00:00:00 2001 From: Junxuan Wu <23434323+atrocitytheme@users.noreply.github.com> Date: Wed, 8 Sep 2021 14:13:33 -0400 Subject: [PATCH] Fix potential NullPointerException in findStoragePool (VolumeOrchestrator) (#5358) * fix null pointer exception when vm is null * add null checker to getPreferredStoragePool method Co-authored-by: junxuan --- .../cloudstack/engine/orchestration/VolumeOrchestrator.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java index 40881cfaa89..3b9397782f5 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java @@ -313,7 +313,10 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati } private Optional getPreferredStoragePool(List poolList, VirtualMachine vm) { - String accountStoragePoolUuid = StorageManager.PreferredStoragePool.valueIn(vm.getAccountId()); + String accountStoragePoolUuid = null; + if (vm != null) { + accountStoragePoolUuid = StorageManager.PreferredStoragePool.valueIn(vm.getAccountId()); + } Optional storagePool = getMatchingStoragePool(accountStoragePoolUuid, poolList); if (storagePool.isPresent()) {