Skip to content

Commit

Permalink
CLOUDSTACK-9796 - Fix NPE in VirtualMachineManagerImpl.java
Browse files Browse the repository at this point in the history
This checks the work variable for NULL in all cases where it is
used.  Fixes CLOUDSTACK-9796.
  • Loading branch information
nathanejohnson committed Feb 21, 2017
1 parent e860249 commit 91bfedd
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -744,14 +744,17 @@ public Ternary<VMInstanceVO, ReservationContext, ItWorkVO> doInTransaction(final

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);
}
}
Expand Down Expand Up @@ -1507,12 +1510,13 @@ private void advanceStop(final VMInstanceVO vm, final boolean cleanUpEvenIfUnabl
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);
Expand Down

0 comments on commit 91bfedd

Please sign in to comment.