Skip to content

Commit 93e66c5

Browse files
authored
Fix null pointer exception in restore VM (apache#431)
1 parent e630d7a commit 93e66c5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

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

7686+
VMTemplateVO template;
7687+
if (newTemplateId != null) {
7688+
template = _templateDao.findById(newTemplateId);
7689+
if (template == null) {
7690+
throw new InvalidParameterValueException("Cannot find template with ID " + newTemplateId);
7691+
}
7692+
} else {
7693+
template = _templateDao.findById(vm.getTemplateId());
7694+
if (template == null) {
7695+
throw new InvalidParameterValueException("Cannot find template linked with VM");
7696+
}
7697+
}
76867698
DiskOffering diskOffering = rootDiskOfferingId != null ? validateAndGetDiskOffering(rootDiskOfferingId, vm, caller) : null;
7687-
VMTemplateVO template = _templateDao.findById(newTemplateId);
76887699
if (template.getSize() != null) {
76897700
String rootDiskSize = details.get(VmDetailConstants.ROOT_DISK_SIZE);
76907701
Long templateSize = template.getSize();

0 commit comments

Comments
 (0)