Skip to content

Commit ebb3089

Browse files
committed
CLOUDSTACK-4008: fix snapshot npe if its volume is deleted
1 parent 3c05999 commit ebb3089

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎engine/api/src/org/apache/cloudstack/storage/to/SnapshotObjectTO.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.cloud.agent.api.to.DataStoreTO;
2323
import com.cloud.agent.api.to.DataTO;
2424
import com.cloud.hypervisor.Hypervisor.HypervisorType;
25+
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
2526

2627
public class SnapshotObjectTO implements DataTO {
2728
private String path;
@@ -40,8 +41,12 @@ public SnapshotObjectTO() {
4041
public SnapshotObjectTO(SnapshotInfo snapshot) {
4142
this.path = snapshot.getPath();
4243
this.setId(snapshot.getId());
43-
this.volume = (VolumeObjectTO) snapshot.getBaseVolume().getTO();
44-
this.setVmName(snapshot.getBaseVolume().getAttachedVmName());
44+
VolumeInfo vol = snapshot.getBaseVolume();
45+
if (vol != null) {
46+
this.volume = (VolumeObjectTO)vol.getTO();
47+
this.setVmName(vol.getAttachedVmName());
48+
}
49+
4550
SnapshotInfo parentSnapshot = snapshot.getParent();
4651
if (parentSnapshot != null) {
4752
this.parentSnapshotPath = parentSnapshot.getPath();

‎engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeDataFactoryImpl.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public VolumeInfo getVolume(long volumeId, DataStoreRole storeRole) {
7474
@Override
7575
public VolumeInfo getVolume(long volumeId) {
7676
VolumeVO volumeVO = volumeDao.findById(volumeId);
77+
if (volumeVO == null) {
78+
return null;
79+
}
7780
VolumeObject vol = null;
7881
if (volumeVO.getPoolId() == null) {
7982
DataStore store = null;

0 commit comments

Comments
 (0)