Skip to content

Commit f2951d9

Browse files
authored
Merge pull request #1956 from myENA/bug/49npe_vmimpl
CLOUDSTACK-9796 - Fix NPE in VirtualMachineManagerImpl.java
2 parents 5fcf648 + 91bfedd commit f2951d9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,14 +744,17 @@ public Ternary<VMInstanceVO, ReservationContext, ItWorkVO> doInTransaction(final
744744

745745
protected <T extends VMInstanceVO> boolean changeState(final T vm, final Event event, final Long hostId, final ItWorkVO work, final Step step) throws NoTransitionException {
746746
// FIXME: We should do this better.
747-
final Step previousStep = work.getStep();
748-
_workDao.updateStep(work, step);
747+
Step previousStep = null;
748+
if (work != null) {
749+
previousStep = work.getStep();
750+
_workDao.updateStep(work, step);
751+
}
749752
boolean result = false;
750753
try {
751754
result = stateTransitTo(vm, event, hostId);
752755
return result;
753756
} finally {
754-
if (!result) {
757+
if (!result && work != null) {
755758
_workDao.updateStep(work, previousStep);
756759
}
757760
}
@@ -1507,12 +1510,13 @@ private void advanceStop(final VMInstanceVO vm, final boolean cleanUpEvenIfUnabl
15071510
if (doCleanup) {
15081511
if (cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.StopRequested, cleanUpEvenIfUnableToStop)) {
15091512
try {
1510-
if (s_logger.isDebugEnabled()) {
1513+
if (s_logger.isDebugEnabled() && work != null) {
15111514
s_logger.debug("Updating work item to Done, id:" + work.getId());
15121515
}
15131516
if (!changeState(vm, Event.AgentReportStopped, null, work, Step.Done)) {
15141517
throw new CloudRuntimeException("Unable to stop " + vm);
15151518
}
1519+
15161520
} catch (final NoTransitionException e) {
15171521
s_logger.warn("Unable to cleanup " + vm);
15181522
throw new CloudRuntimeException("Unable to stop " + vm, e);

0 commit comments

Comments
 (0)