Program: 106252
Project: 106252
Buggy source:
private void deleteTemplate(DataObject data,AsyncCompletionCallback<CommandResult> callback){
  TemplateObject templateObj=(TemplateObject)data;
  VMTemplateVO template=templateObj.getImage();
  ImageStoreImpl store=(ImageStoreImpl)templateObj.getDataStore();
  long storeId=store.getId();
  Long sZoneId=store.getDataCenterId();
  long templateId=template.getId();
  Account account=_accountDao.findByIdIncludingRemoved(template.getAccountId());
  String eventType="String_Node_Str";
  if (template.getFormat().equals(ImageFormat.ISO)) {
    eventType=EventTypes.EVENT_ISO_DELETE;
  }
 else {
    eventType=EventTypes.EVENT_TEMPLATE_DELETE;
  }
  UsageEventUtils.publishUsageEvent(eventType,account.getId(),sZoneId,templateId,null,null,null);
  List<UserVmVO> userVmUsingIso=_userVmDao.listByIsoId(templateId);
  if (userVmUsingIso == null || userVmUsingIso.isEmpty()) {
    TemplateDataStoreVO tmplStore=_templateStoreDao.findByStoreTemplate(storeId,templateId);
    String installPath=tmplStore.getInstallPath();
    if (installPath != null) {
      DeleteTemplateCommand cmd=new DeleteTemplateCommand(store.getTO(),installPath,template.getId(),template.getAccountId());
      EndPoint ep=_epSelector.select(templateObj);
      Answer answer=ep.sendMessage(cmd);
      if (answer == null || !answer.getResult()) {
        s_logger.debug("String_Node_Str" + store.getName());
        CommandResult result=new CommandResult();
        result.setResult("String_Node_Str");
        callback.complete(result);
      }
 else {
        s_logger.debug("String_Node_Str" + installPath);
        CommandResult result=new CommandResult();
        callback.complete(result);
      }
      List<VMTemplateZoneVO> templateZones=templateZoneDao.listByZoneTemplate(sZoneId,templateId);
      if (templateZones != null) {
        for (        VMTemplateZoneVO templateZone : templateZones) {
          templateZoneDao.remove(templateZone.getId());
        }
      }
    }
  }
}

Fixed version (ground truth):
private void deleteTemplate(DataObject data,AsyncCompletionCallback<CommandResult> callback){
  TemplateObject templateObj=(TemplateObject)data;
  VMTemplateVO template=templateObj.getImage();
  ImageStoreImpl store=(ImageStoreImpl)templateObj.getDataStore();
  long storeId=store.getId();
  Long sZoneId=store.getDataCenterId();
  long templateId=template.getId();
  Account account=_accountDao.findByIdIncludingRemoved(template.getAccountId());
  String eventType="String_Node_Str";
  if (template.getFormat().equals(ImageFormat.ISO)) {
    eventType=EventTypes.EVENT_ISO_DELETE;
  }
 else {
    eventType=EventTypes.EVENT_TEMPLATE_DELETE;
  }
  UsageEventUtils.publishUsageEvent(eventType,account.getId(),sZoneId,templateId,null,null,null);
  List<UserVmVO> userVmUsingIso=_userVmDao.listByIsoId(templateId);
  if (userVmUsingIso == null || userVmUsingIso.isEmpty()) {
    TemplateDataStoreVO tmplStore=_templateStoreDao.findByStoreTemplate(storeId,templateId);
    String installPath=tmplStore.getInstallPath();
    if (installPath != null) {
      DeleteTemplateCommand cmd=new DeleteTemplateCommand(store.getTO(),installPath,template.getId(),template.getAccountId());
      EndPoint ep=_epSelector.select(templateObj);
      Answer answer=ep.sendMessage(cmd);
      if (answer == null || !answer.getResult()) {
        s_logger.debug("String_Node_Str" + store.getName());
        CommandResult result=new CommandResult();
        result.setResult("String_Node_Str");
        callback.complete(result);
      }
 else {
        s_logger.debug("String_Node_Str" + installPath);
        CommandResult result=new CommandResult();
        callback.complete(result);
      }
      List<VMTemplateZoneVO> templateZones=templateZoneDao.listByZoneTemplate(sZoneId,templateId);
      if (templateZones != null) {
        for (        VMTemplateZoneVO templateZone : templateZones) {
          templateZoneDao.remove(templateZone.getId());
        }
      }
    }
  }
 else {
    s_logger.debug("String_Node_Str");
    CommandResult result=new CommandResult();
    result.setResult("String_Node_Str");
    callback.complete(result);
  }
}