From 4b8bfe26275f7eb6e98abe77849153eaa93e8205 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Tue, 14 Oct 2014 10:35:29 -0700 Subject: [PATCH] CLOUDSTACK-7563: Fix potential NPE from FingBugs. --- .../com/cloud/vm/VirtualMachineManagerImpl.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java index d458950f5ad..de2fd28e3a1 100755 --- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -1873,7 +1873,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { pfma = _agentMgr.send(dstHostId, pfmc); if (pfma == null || !pfma.getResult()) { - String msg = "Unable to prepare for migration due to " + pfma.getDetails(); + String details = (pfma != null) ? pfma.getDetails() : "null answer returned"; + String msg = "Unable to prepare for migration due to " + details; pfma = null; throw new AgentUnavailableException(msg, dstHostId); } @@ -1909,7 +1910,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { Answer ma = _agentMgr.send(vm.getLastHostId(), mc); if (ma == null || !ma.getResult()) { - throw new CloudRuntimeException("Unable to migrate due to " + ma.getDetails()); + String details = (ma != null) ? ma.getDetails() : "null answer returned"; + throw new CloudRuntimeException("Unable to migrate due to " + details); } } catch (OperationTimedoutException e) { if (e.isActive()) { @@ -3263,7 +3265,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { pfma = _agentMgr.send(dstHostId, pfmc); if (pfma == null || !pfma.getResult()) { - String msg = "Unable to prepare for migration due to " + pfma.getDetails(); + String details = (pfma != null) ? pfma.getDetails() : "null answer returned"; + String msg = "Unable to prepare for migration due to " + details; pfma = null; throw new AgentUnavailableException(msg, dstHostId); } @@ -3296,8 +3299,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { Answer ma = _agentMgr.send(vm.getLastHostId(), mc); if (ma == null || !ma.getResult()) { - s_logger.error("Unable to migrate due to " + ma.getDetails()); - throw new CloudRuntimeException("Unable to migrate due to " + ma.getDetails()); + String details = (ma != null) ? ma.getDetails() : "null answer returned"; + String msg = "Unable to migrate due to " + details; + s_logger.error(msg); + throw new CloudRuntimeException(msg); } } catch (OperationTimedoutException e) { if (e.isActive()) {