Program: 106254
Project: 106254
Buggy source:
@Override public void processEvent(ObjectInDataStoreStateMachine.Event event,Answer answer){
  try {
    if (this.getDataStore().getRole() == DataStoreRole.Primary) {
      if (answer instanceof CopyCmdAnswer) {
        CopyCmdAnswer cpyAnswer=(CopyCmdAnswer)answer;
        TemplateObjectTO newTemplate=(TemplateObjectTO)cpyAnswer.getNewData();
        VMTemplateStoragePoolVO templatePoolRef=templatePoolDao.findByPoolTemplate(this.getDataStore().getId(),this.getId());
        templatePoolRef.setDownloadPercent(100);
        templatePoolRef.setDownloadState(Status.DOWNLOADED);
        templatePoolRef.setLocalDownloadPath(newTemplate.getPath());
        templatePoolRef.setInstallPath(newTemplate.getPath());
        templatePoolDao.update(templatePoolRef.getId(),templatePoolRef);
      }
    }
 else     if (this.getDataStore().getRole() == DataStoreRole.Image || this.getDataStore().getRole() == DataStoreRole.ImageCache) {
      if (answer instanceof CopyCmdAnswer) {
        CopyCmdAnswer cpyAnswer=(CopyCmdAnswer)answer;
        TemplateObjectTO newTemplate=(TemplateObjectTO)cpyAnswer.getNewData();
        TemplateDataStoreVO templateStoreRef=this.templateStoreDao.findByStoreTemplate(this.getDataStore().getId(),this.getId());
        templateStoreRef.setInstallPath(newTemplate.getPath());
        templateStoreRef.setDownloadPercent(100);
        templateStoreRef.setDownloadState(Status.DOWNLOADED);
        templateStoreDao.update(templateStoreRef.getId(),templateStoreRef);
        if (this.getDataStore().getRole() == DataStoreRole.Image) {
          VMTemplateVO templateVO=this.imageDao.findById(this.getId());
          templateVO.setFormat(newTemplate.getFormat());
          templateVO.setSize(newTemplate.getSize());
          this.imageDao.update(templateVO.getId(),templateVO);
        }
      }
      TemplateEvent templEvent=null;
      if (event == ObjectInDataStoreStateMachine.Event.CreateOnlyRequested) {
        templEvent=TemplateEvent.CreateRequested;
      }
 else       if (event == ObjectInDataStoreStateMachine.Event.DestroyRequested) {
        templEvent=TemplateEvent.DestroyRequested;
      }
 else       if (event == ObjectInDataStoreStateMachine.Event.OperationSuccessed) {
        templEvent=TemplateEvent.OperationSucceeded;
      }
 else       if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
        templEvent=TemplateEvent.OperationFailed;
      }
      if (templEvent != null && this.getDataStore().getRole() == DataStoreRole.Image) {
        this.stateTransit(templEvent);
      }
    }
    ojbectInStoreMgr.update(this,event);
  }
 catch (  NoTransitionException e) {
    s_logger.debug("String_Node_Str",e);
    throw new CloudRuntimeException("String_Node_Str" + e.toString());
  }
}

Fixed version (ground truth):
@Override public void processEvent(ObjectInDataStoreStateMachine.Event event,Answer answer){
  try {
    if (this.getDataStore().getRole() == DataStoreRole.Primary) {
      if (answer instanceof CopyCmdAnswer) {
        CopyCmdAnswer cpyAnswer=(CopyCmdAnswer)answer;
        TemplateObjectTO newTemplate=(TemplateObjectTO)cpyAnswer.getNewData();
        VMTemplateStoragePoolVO templatePoolRef=templatePoolDao.findByPoolTemplate(this.getDataStore().getId(),this.getId());
        templatePoolRef.setDownloadPercent(100);
        templatePoolRef.setDownloadState(Status.DOWNLOADED);
        templatePoolRef.setLocalDownloadPath(newTemplate.getPath());
        templatePoolRef.setInstallPath(newTemplate.getPath());
        templatePoolDao.update(templatePoolRef.getId(),templatePoolRef);
      }
    }
 else     if (this.getDataStore().getRole() == DataStoreRole.Image || this.getDataStore().getRole() == DataStoreRole.ImageCache) {
      if (answer instanceof CopyCmdAnswer) {
        CopyCmdAnswer cpyAnswer=(CopyCmdAnswer)answer;
        TemplateObjectTO newTemplate=(TemplateObjectTO)cpyAnswer.getNewData();
        TemplateDataStoreVO templateStoreRef=this.templateStoreDao.findByStoreTemplate(this.getDataStore().getId(),this.getId());
        templateStoreRef.setInstallPath(newTemplate.getPath());
        templateStoreRef.setDownloadPercent(100);
        templateStoreRef.setDownloadState(Status.DOWNLOADED);
        templateStoreRef.setSize(newTemplate.getSize());
        templateStoreDao.update(templateStoreRef.getId(),templateStoreRef);
        if (this.getDataStore().getRole() == DataStoreRole.Image) {
          VMTemplateVO templateVO=this.imageDao.findById(this.getId());
          templateVO.setFormat(newTemplate.getFormat());
          templateVO.setSize(newTemplate.getSize());
          this.imageDao.update(templateVO.getId(),templateVO);
        }
      }
      TemplateEvent templEvent=null;
      if (event == ObjectInDataStoreStateMachine.Event.CreateOnlyRequested) {
        templEvent=TemplateEvent.CreateRequested;
      }
 else       if (event == ObjectInDataStoreStateMachine.Event.DestroyRequested) {
        templEvent=TemplateEvent.DestroyRequested;
      }
 else       if (event == ObjectInDataStoreStateMachine.Event.OperationSuccessed) {
        templEvent=TemplateEvent.OperationSucceeded;
      }
 else       if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
        templEvent=TemplateEvent.OperationFailed;
      }
      if (templEvent != null && this.getDataStore().getRole() == DataStoreRole.Image) {
        this.stateTransit(templEvent);
      }
    }
    ojbectInStoreMgr.update(this,event);
  }
 catch (  NoTransitionException e) {
    s_logger.debug("String_Node_Str",e);
    throw new CloudRuntimeException("String_Node_Str" + e.toString());
  }
}