CLOUDSTACK-9796 - Fix NPE in VirtualMachineManagerImpl.java

This checks the work variable for NULL in all cases where it is
used.  Fixes CLOUDSTACK-9796.
This commit is contained in:
Nathan Johnson 2017-02-20 14:58:20 -06:00
parent e860249e4f
commit 91bfedd2c7
1 changed files with 8 additions and 4 deletions

View File

@ -744,14 +744,17 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
protected <T extends VMInstanceVO> boolean changeState(final T vm, final Event event, final Long hostId, final ItWorkVO work, final Step step) throws NoTransitionException {
// FIXME: We should do this better.
final Step previousStep = work.getStep();
_workDao.updateStep(work, step);
Step previousStep = null;
if (work != null) {
previousStep = work.getStep();
_workDao.updateStep(work, step);
}
boolean result = false;
try {
result = stateTransitTo(vm, event, hostId);
return result;
} finally {
if (!result) {
if (!result && work != null) {
_workDao.updateStep(work, previousStep);
}
}
@ -1507,12 +1510,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
if (doCleanup) {
if (cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.StopRequested, cleanUpEvenIfUnableToStop)) {
try {
if (s_logger.isDebugEnabled()) {
if (s_logger.isDebugEnabled() && work != null) {
s_logger.debug("Updating work item to Done, id:" + work.getId());
}
if (!changeState(vm, Event.AgentReportStopped, null, work, Step.Done)) {
throw new CloudRuntimeException("Unable to stop " + vm);
}
} catch (final NoTransitionException e) {
s_logger.warn("Unable to cleanup " + vm);
throw new CloudRuntimeException("Unable to stop " + vm, e);