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 <atrocitythemetms@gmail.com>
This commit is contained in:
Junxuan Wu 2021-09-08 14:13:33 -04:00 committed by GitHub
parent 30aeeb09d2
commit f6073052aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -313,7 +313,10 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
}
private Optional<StoragePool> getPreferredStoragePool(List<StoragePool> poolList, VirtualMachine vm) {
String accountStoragePoolUuid = StorageManager.PreferredStoragePool.valueIn(vm.getAccountId());
String accountStoragePoolUuid = null;
if (vm != null) {
accountStoragePoolUuid = StorageManager.PreferredStoragePool.valueIn(vm.getAccountId());
}
Optional<StoragePool> storagePool = getMatchingStoragePool(accountStoragePoolUuid, poolList);
if (storagePool.isPresent()) {