Skip to content

Commit 3a5a8ec

Browse files
vishesh92dhslove
authored andcommitted
server: Fix null pointer exception in restore VM (apache#8930)
1 parent 59a0f7d commit 3a5a8ec

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8188,8 +8188,19 @@ public UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException,
81888188
}
81898189
_accountMgr.checkAccess(caller, null, true, vm);
81908190

8191+
VMTemplateVO template;
8192+
if (newTemplateId != null) {
8193+
template = _templateDao.findById(newTemplateId);
8194+
if (template == null) {
8195+
throw new InvalidParameterValueException("Cannot find template with ID " + newTemplateId);
8196+
}
8197+
} else {
8198+
template = _templateDao.findById(vm.getTemplateId());
8199+
if (template == null) {
8200+
throw new InvalidParameterValueException("Cannot find template linked with VM");
8201+
}
8202+
}
81918203
DiskOffering diskOffering = rootDiskOfferingId != null ? validateAndGetDiskOffering(rootDiskOfferingId, vm, caller) : null;
8192-
VMTemplateVO template = _templateDao.findById(newTemplateId);
81938204
if (template.getSize() != null) {
81948205
String rootDiskSize = details.get(VmDetailConstants.ROOT_DISK_SIZE);
81958206
Long templateSize = template.getSize();

0 commit comments

Comments
 (0)