Program: 106261
Project: 106261
Buggy source:
@Override public DataObject create(DataObject obj,DataStore dataStore){
  if (dataStore.getRole() == DataStoreRole.Primary) {
    if (obj.getType() == DataObjectType.TEMPLATE) {
      VMTemplateStoragePoolVO vo=new VMTemplateStoragePoolVO(dataStore.getId(),obj.getId());
      vo=templatePoolDao.persist(vo);
    }
 else     if (obj.getType() == DataObjectType.SNAPSHOT) {
      SnapshotDataStoreVO ss=new SnapshotDataStoreVO();
      ss.setSnapshotId(obj.getId());
      ss.setDataStoreId(dataStore.getId());
      ss.setRole(dataStore.getRole());
      ss.setState(ObjectInDataStoreStateMachine.State.Allocated);
      ss=snapshotDataStoreDao.persist(ss);
    }
  }
 else {
switch (obj.getType()) {
case TEMPLATE:
      TemplateDataStoreVO ts=new TemplateDataStoreVO();
    ts.setTemplateId(obj.getId());
  ts.setDataStoreId(dataStore.getId());
ts.setInstallPath(TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "String_Node_Str" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR+ templateDao.findById(obj.getId()).getAccountId()+ "String_Node_Str"+ obj.getId());
ts.setState(ObjectInDataStoreStateMachine.State.Allocated);
ts=templateDataStoreDao.persist(ts);
break;
case SNAPSHOT:
SnapshotDataStoreVO ss=new SnapshotDataStoreVO();
ss.setSnapshotId(obj.getId());
ss.setDataStoreId(dataStore.getId());
ss.setRole(dataStore.getRole());
ss.setInstallPath(TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR + "String_Node_Str" + snapshotDao.findById(obj.getId()).getAccountId()+ "String_Node_Str"+ obj.getId());
ss.setState(ObjectInDataStoreStateMachine.State.Allocated);
ss=snapshotDataStoreDao.persist(ss);
break;
case VOLUME:
VolumeDataStoreVO vs=new VolumeDataStoreVO();
vs.setVolumeId(obj.getId());
vs.setDataStoreId(dataStore.getId());
vs.setInstallPath(TemplateConstants.DEFAULT_VOLUME_ROOT_DIR + "String_Node_Str" + volumeDao.findById(obj.getId()).getAccountId()+ "String_Node_Str"+ obj.getId());
vs.setState(ObjectInDataStoreStateMachine.State.Allocated);
vs=volumeDataStoreDao.persist(vs);
break;
}
}
return this.get(obj,dataStore);
}

Fixed version (ground truth):
@Override public DataObject create(DataObject obj,DataStore dataStore){
  if (dataStore.getRole() == DataStoreRole.Primary) {
    if (obj.getType() == DataObjectType.TEMPLATE) {
      VMTemplateStoragePoolVO vo=new VMTemplateStoragePoolVO(dataStore.getId(),obj.getId());
      vo=templatePoolDao.persist(vo);
    }
 else     if (obj.getType() == DataObjectType.SNAPSHOT) {
      SnapshotDataStoreVO ss=new SnapshotDataStoreVO();
      ss.setSnapshotId(obj.getId());
      ss.setDataStoreId(dataStore.getId());
      ss.setRole(dataStore.getRole());
      ss.setState(ObjectInDataStoreStateMachine.State.Allocated);
      ss=snapshotDataStoreDao.persist(ss);
    }
  }
 else {
switch (obj.getType()) {
case TEMPLATE:
      TemplateDataStoreVO ts=new TemplateDataStoreVO();
    ts.setTemplateId(obj.getId());
  ts.setDataStoreId(dataStore.getId());
ts.setDataStoreRole(dataStore.getRole());
ts.setInstallPath(TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "String_Node_Str" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR+ templateDao.findById(obj.getId()).getAccountId()+ "String_Node_Str"+ obj.getId());
ts.setState(ObjectInDataStoreStateMachine.State.Allocated);
ts=templateDataStoreDao.persist(ts);
break;
case SNAPSHOT:
SnapshotDataStoreVO ss=new SnapshotDataStoreVO();
ss.setSnapshotId(obj.getId());
ss.setDataStoreId(dataStore.getId());
ss.setRole(dataStore.getRole());
ss.setRole(dataStore.getRole());
ss.setInstallPath(TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR + "String_Node_Str" + snapshotDao.findById(obj.getId()).getAccountId()+ "String_Node_Str"+ obj.getId());
ss.setState(ObjectInDataStoreStateMachine.State.Allocated);
ss=snapshotDataStoreDao.persist(ss);
break;
case VOLUME:
VolumeDataStoreVO vs=new VolumeDataStoreVO();
vs.setVolumeId(obj.getId());
vs.setDataStoreId(dataStore.getId());
vs.setInstallPath(TemplateConstants.DEFAULT_VOLUME_ROOT_DIR + "String_Node_Str" + volumeDao.findById(obj.getId()).getAccountId()+ "String_Node_Str"+ obj.getId());
vs.setState(ObjectInDataStoreStateMachine.State.Allocated);
vs=volumeDataStoreDao.persist(vs);
break;
}
}
return this.get(obj,dataStore);
}