Program: 106274
Project: 106274
Buggy source:
protected Void createAsyncCallback(AsyncCallbackDispatcher<SwiftImageStoreDriverImpl,DownloadAnswer> callback,CreateContext<CreateCmdResult> context){
  DownloadAnswer answer=callback.getResult();
  DataObject obj=context.data;
  DataStore store=obj.getDataStore();
  TemplateDataStoreVO updateBuilder=_templateStoreDao.createForUpdate();
  updateBuilder.setDownloadPercent(answer.getDownloadPct());
  updateBuilder.setDownloadState(answer.getDownloadStatus());
  updateBuilder.setLastUpdated(new Date());
  updateBuilder.setErrorString(answer.getErrorString());
  updateBuilder.setJobId(answer.getJobId());
  updateBuilder.setLocalDownloadPath(answer.getDownloadPath());
  updateBuilder.setInstallPath(answer.getInstallPath());
  updateBuilder.setSize(answer.getTemplateSize());
  updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize());
  _templateStoreDao.update(store.getId(),updateBuilder);
  AsyncCompletionCallback<CreateCmdResult> caller=context.getParentCallback();
  if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN) {
    CreateCmdResult result=new CreateCmdResult(null,null);
    result.setSucess(false);
    result.setResult(answer.getErrorString());
    caller.complete(result);
  }
 else   if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
    if (answer.getCheckSum() != null) {
      VMTemplateVO templateDaoBuilder=templateDao.createForUpdate();
      templateDaoBuilder.setChecksum(answer.getCheckSum());
      templateDao.update(obj.getId(),templateDaoBuilder);
    }
    CreateCmdResult result=new CreateCmdResult(null,null);
    caller.complete(result);
  }
  return null;
}

Fixed version (ground truth):
protected Void createAsyncCallback(AsyncCallbackDispatcher<SwiftImageStoreDriverImpl,DownloadAnswer> callback,CreateContext<CreateCmdResult> context){
  DownloadAnswer answer=callback.getResult();
  DataObject obj=context.data;
  DataStore store=obj.getDataStore();
  TemplateDataStoreVO tmpltStoreVO=_templateStoreDao.findByStoreTemplate(store.getId(),obj.getId());
  if (tmpltStoreVO != null) {
    TemplateDataStoreVO updateBuilder=_templateStoreDao.createForUpdate();
    updateBuilder.setDownloadPercent(answer.getDownloadPct());
    updateBuilder.setDownloadState(answer.getDownloadStatus());
    updateBuilder.setLastUpdated(new Date());
    updateBuilder.setErrorString(answer.getErrorString());
    updateBuilder.setJobId(answer.getJobId());
    updateBuilder.setLocalDownloadPath(answer.getDownloadPath());
    updateBuilder.setInstallPath(answer.getInstallPath());
    updateBuilder.setSize(answer.getTemplateSize());
    updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize());
    _templateStoreDao.update(tmpltStoreVO.getId(),updateBuilder);
  }
  AsyncCompletionCallback<CreateCmdResult> caller=context.getParentCallback();
  if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN) {
    CreateCmdResult result=new CreateCmdResult(null,null);
    result.setSucess(false);
    result.setResult(answer.getErrorString());
    caller.complete(result);
  }
 else   if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
    if (answer.getCheckSum() != null) {
      VMTemplateVO templateDaoBuilder=templateDao.createForUpdate();
      templateDaoBuilder.setChecksum(answer.getCheckSum());
      templateDao.update(obj.getId(),templateDaoBuilder);
    }
    CreateCmdResult result=new CreateCmdResult(null,null);
    caller.complete(result);
  }
  return null;
}