Program: 125385
Project: 125385
Buggy source:
protected void doImportItem(IProgressMonitor monitor,ResourcesManager resManager,ImportItem selectedImportItem,boolean overwrite,IPath destinationPath,Set<String> overwriteDeletedItems,Set<String> idDeletedBeforeImport){
  final Item item=selectedImportItem.getItem();
  if (item != null) {
    final ProxyRepositoryFactory repFactory=ProxyRepositoryFactory.getInstance();
    ERepositoryObjectType itemType=ERepositoryObjectType.getItemType(item);
    IPath path=checkAndCreatePath(selectedImportItem,destinationPath);
    try {
      Item tmpItem=item;
      String id=selectedImportItem.getProperty().getId();
      IRepositoryViewObject lastVersion=selectedImportItem.getExistingItemWithSameId();
      if (selectedImportItem.getState() == State.NAME_EXISTED || selectedImportItem.getState() == State.NAME_AND_ID_EXISTED_BOTH) {
        lastVersion=selectedImportItem.getExistingItemWithSameName();
      }
      if (lastVersion != null && overwrite && !selectedImportItem.isLocked() && (selectedImportItem.getState() == State.ID_EXISTED || selectedImportItem.getState() == State.NAME_EXISTED || selectedImportItem.getState() == State.NAME_AND_ID_EXISTED || selectedImportItem.getState() == State.NAME_AND_ID_EXISTED_BOTH) && !ImportCacheHelper.getInstance().getDeletedItems().contains(id)) {
        if (overwriteDeletedItems != null && !overwriteDeletedItems.contains(id)) {
          ERepositoryStatus status=repFactory.getStatus(lastVersion);
          if (status == ERepositoryStatus.DELETED) {
            repFactory.restoreObject(lastVersion,path);
          }
          overwriteDeletedItems.add(id);
        }
        if (selectedImportItem.getState().equals(ImportItem.State.NAME_EXISTED) || selectedImportItem.getState().equals(ImportItem.State.NAME_AND_ID_EXISTED) || selectedImportItem.getState().equals(ImportItem.State.NAME_AND_ID_EXISTED_BOTH)) {
          final IRepositoryViewObject lastVersionBackup=lastVersion;
          if (idDeletedBeforeImport != null && !idDeletedBeforeImport.contains(id)) {
            final List<IRepositoryViewObject> allVersionToDelete=repFactory.getAllVersion(ProjectManager.getInstance().getCurrentProject(),lastVersionBackup.getId(),false);
            String importingLabel=selectedImportItem.getProperty().getLabel();
            String existLabel=lastVersionBackup.getProperty().getLabel();
            boolean isDeleteOnRemote=isNeedDeleteOnRemote(importingLabel,existLabel);
            RepositoryWorkUnit repositoryWorkUnit=new RepositoryWorkUnit(Messages.getString("String_Node_Str")){
              @Override public void run() throws PersistenceException {
                for (                IRepositoryViewObject currentVersion : allVersionToDelete) {
                  repFactory.forceDeleteObjectPhysical(lastVersionBackup,currentVersion.getVersion(),isDeleteOnRemote);
                }
              }
            }
;
            if (isDeleteOnRemote) {
              repositoryWorkUnit.setForceTransaction(true);
            }
 else {
              repositoryWorkUnit.setForceTransaction(false);
            }
            repositoryWorkUnit.setRefreshRepository(false);
            ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
            idDeletedBeforeImport.add(id);
          }
        }
        lastVersion=null;
      }
      User author=selectedImportItem.getProperty().getAuthor();
      if (author != null) {
        if (!repFactory.setAuthorByLogin(tmpItem,author.getLogin())) {
          tmpItem.getProperty().setAuthor(null);
        }
      }
      beforeCreatingItem(selectedImportItem);
      final RepositoryObjectCache repObjectcache=ImportCacheHelper.getInstance().getRepObjectcache();
      if (lastVersion == null || selectedImportItem.getState().equals(ImportItem.State.ID_EXISTED) || selectedImportItem.getState().equals(ImportItem.State.NAME_AND_ID_EXISTED_BOTH)) {
        repFactory.create(tmpItem,path,true);
        afterCreatedItem(resManager,selectedImportItem);
        selectedImportItem.setImported(true);
      }
 else       if (VersionUtils.compareTo(lastVersion.getProperty().getVersion(),tmpItem.getProperty().getVersion()) < 0) {
        repFactory.forceCreate(tmpItem,path);
        afterForceCreatedItem(resManager,selectedImportItem);
        selectedImportItem.setImported(true);
      }
 else {
        PersistenceException e=new PersistenceException(Messages.getString("String_Node_Str",tmpItem.getProperty()));
        selectedImportItem.addError(e.getMessage());
        logError(e);
      }
      if (selectedImportItem.isImported()) {
        selectedImportItem.setImportPath(path.toPortableString());
        selectedImportItem.setRepositoryType(itemType);
        selectedImportItem.setItemId(selectedImportItem.getProperty().getId());
        selectedImportItem.setItemVersion(selectedImportItem.getProperty().getVersion());
        repObjectcache.addToCache(tmpItem);
      }
      if (tmpItem.getState() != null && itemType != null) {
        final Set<String> folders=ImportCacheHelper.getInstance().getRestoreFolder().getFolders(itemType);
        if (folders != null) {
          for (          String folderPath : folders) {
            if (folderPath != null && folderPath.equals(path.toString())) {
              FolderItem folderItem=repFactory.getFolderItem(ProjectManager.getInstance().getCurrentProject(),itemType,path);
              if (folderItem != null) {
                folderItem.getState().setDeleted(false);
                while (!(folderItem.getParent() instanceof Project)) {
                  folderItem=(FolderItem)folderItem.getParent();
                  if (folderItem.getType() == FolderType.SYSTEM_FOLDER_LITERAL) {
                    break;
                  }
                  folderItem.getState().setDeleted(false);
                }
              }
              break;
            }
          }
        }
      }
    }
 catch (    Exception e) {
      selectedImportItem.addError(selectedImportItem.getItemName() + "String_Node_Str" + e.getMessage()+ "String_Node_Str"+ path);
      logError(e);
    }
  }
}

Fixed version (ground truth):
protected void doImportItem(IProgressMonitor monitor,ResourcesManager resManager,ImportItem selectedImportItem,boolean overwrite,IPath destinationPath,Set<String> overwriteDeletedItems,Set<String> idDeletedBeforeImport){
  final Item item=selectedImportItem.getItem();
  if (item != null) {
    final ProxyRepositoryFactory repFactory=ProxyRepositoryFactory.getInstance();
    ERepositoryObjectType itemType=ERepositoryObjectType.getItemType(item);
    IPath path=checkAndCreatePath(selectedImportItem,destinationPath);
    try {
      Item tmpItem=item;
      String id=selectedImportItem.getProperty().getId();
      IRepositoryViewObject lastVersion=selectedImportItem.getExistingItemWithSameId();
      if (selectedImportItem.getState() == State.NAME_EXISTED || selectedImportItem.getState() == State.NAME_AND_ID_EXISTED_BOTH) {
        lastVersion=selectedImportItem.getExistingItemWithSameName();
      }
      if (lastVersion != null && overwrite && !selectedImportItem.isLocked() && (selectedImportItem.getState() == State.ID_EXISTED || selectedImportItem.getState() == State.NAME_EXISTED || selectedImportItem.getState() == State.NAME_AND_ID_EXISTED || selectedImportItem.getState() == State.NAME_AND_ID_EXISTED_BOTH) && !ImportCacheHelper.getInstance().getDeletedItems().contains(id)) {
        if (overwriteDeletedItems != null && !overwriteDeletedItems.contains(id)) {
          ERepositoryStatus status=repFactory.getStatus(lastVersion);
          if (status == ERepositoryStatus.DELETED) {
            repFactory.restoreObject(lastVersion,path);
          }
          overwriteDeletedItems.add(id);
        }
        if (selectedImportItem.getState().equals(ImportItem.State.NAME_EXISTED) || selectedImportItem.getState().equals(ImportItem.State.NAME_AND_ID_EXISTED) || selectedImportItem.getState().equals(ImportItem.State.NAME_AND_ID_EXISTED_BOTH)) {
          final IRepositoryViewObject lastVersionBackup=lastVersion;
          if (idDeletedBeforeImport != null && !idDeletedBeforeImport.contains(id)) {
            final List<IRepositoryViewObject> allVersionToDelete=repFactory.getAllVersion(ProjectManager.getInstance().getCurrentProject(),lastVersionBackup.getId(),false);
            String importingLabel=selectedImportItem.getProperty().getLabel();
            String existLabel=lastVersionBackup.getProperty().getLabel();
            final boolean isDeleteOnRemote=isNeedDeleteOnRemote(importingLabel,existLabel);
            RepositoryWorkUnit repositoryWorkUnit=new RepositoryWorkUnit(Messages.getString("String_Node_Str")){
              @Override public void run() throws PersistenceException {
                for (                IRepositoryViewObject currentVersion : allVersionToDelete) {
                  repFactory.forceDeleteObjectPhysical(lastVersionBackup,currentVersion.getVersion(),isDeleteOnRemote);
                }
              }
            }
;
            if (isDeleteOnRemote) {
              repositoryWorkUnit.setForceTransaction(true);
            }
 else {
              repositoryWorkUnit.setForceTransaction(false);
            }
            repositoryWorkUnit.setRefreshRepository(false);
            ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
            idDeletedBeforeImport.add(id);
          }
        }
        lastVersion=null;
      }
      User author=selectedImportItem.getProperty().getAuthor();
      if (author != null) {
        if (!repFactory.setAuthorByLogin(tmpItem,author.getLogin())) {
          tmpItem.getProperty().setAuthor(null);
        }
      }
      beforeCreatingItem(selectedImportItem);
      final RepositoryObjectCache repObjectcache=ImportCacheHelper.getInstance().getRepObjectcache();
      if (lastVersion == null || selectedImportItem.getState().equals(ImportItem.State.ID_EXISTED) || selectedImportItem.getState().equals(ImportItem.State.NAME_AND_ID_EXISTED_BOTH)) {
        repFactory.create(tmpItem,path,true);
        afterCreatedItem(resManager,selectedImportItem);
        selectedImportItem.setImported(true);
      }
 else       if (VersionUtils.compareTo(lastVersion.getProperty().getVersion(),tmpItem.getProperty().getVersion()) < 0) {
        repFactory.forceCreate(tmpItem,path);
        afterForceCreatedItem(resManager,selectedImportItem);
        selectedImportItem.setImported(true);
      }
 else {
        PersistenceException e=new PersistenceException(Messages.getString("String_Node_Str",tmpItem.getProperty()));
        selectedImportItem.addError(e.getMessage());
        logError(e);
      }
      if (selectedImportItem.isImported()) {
        selectedImportItem.setImportPath(path.toPortableString());
        selectedImportItem.setRepositoryType(itemType);
        selectedImportItem.setItemId(selectedImportItem.getProperty().getId());
        selectedImportItem.setItemVersion(selectedImportItem.getProperty().getVersion());
        repObjectcache.addToCache(tmpItem);
      }
      if (tmpItem.getState() != null && itemType != null) {
        final Set<String> folders=ImportCacheHelper.getInstance().getRestoreFolder().getFolders(itemType);
        if (folders != null) {
          for (          String folderPath : folders) {
            if (folderPath != null && folderPath.equals(path.toString())) {
              FolderItem folderItem=repFactory.getFolderItem(ProjectManager.getInstance().getCurrentProject(),itemType,path);
              if (folderItem != null) {
                folderItem.getState().setDeleted(false);
                while (!(folderItem.getParent() instanceof Project)) {
                  folderItem=(FolderItem)folderItem.getParent();
                  if (folderItem.getType() == FolderType.SYSTEM_FOLDER_LITERAL) {
                    break;
                  }
                  folderItem.getState().setDeleted(false);
                }
              }
              break;
            }
          }
        }
      }
    }
 catch (    Exception e) {
      selectedImportItem.addError(selectedImportItem.getItemName() + "String_Node_Str" + e.getMessage()+ "String_Node_Str"+ path);
      logError(e);
    }
  }
}