Program: 126476
Project: 126476
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 (lastVersion != null && overwrite && !selectedImportItem.isLocked() && (selectedImportItem.getState() == State.ID_EXISTED || selectedImportItem.getState() == State.NAME_EXISTED || selectedImportItem.getState() == State.NAME_AND_ID_EXISTED) && !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)) {
          final IRepositoryViewObject lastVersionBackup=lastVersion;
          if (idDeletedBeforeImport != null && !idDeletedBeforeImport.contains(id)) {
            final List<IRepositoryViewObject> allVersionToDelete=repFactory.getAllVersion(ProjectManager.getInstance().getCurrentProject(),lastVersionBackup.getId(),false);
            RepositoryWorkUnit repositoryWorkUnit=new RepositoryWorkUnit(Messages.getString("String_Node_Str")){
              @Override public void run() throws PersistenceException {
                for (                IRepositoryViewObject currentVersion : allVersionToDelete) {
                  repFactory.forceDeleteObjectPhysical(lastVersionBackup,currentVersion.getVersion());
                }
              }
            }
;
            repositoryWorkUnit.setForceTransaction(true);
            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)) {
        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(e.getMessage());
      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 (lastVersion != null && overwrite && !selectedImportItem.isLocked() && (selectedImportItem.getState() == State.ID_EXISTED || selectedImportItem.getState() == State.NAME_EXISTED || selectedImportItem.getState() == State.NAME_AND_ID_EXISTED) && !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)) {
          final IRepositoryViewObject lastVersionBackup=lastVersion;
          if (idDeletedBeforeImport != null && !idDeletedBeforeImport.contains(id)) {
            final List<IRepositoryViewObject> allVersionToDelete=repFactory.getAllVersion(ProjectManager.getInstance().getCurrentProject(),lastVersionBackup.getId(),false);
            RepositoryWorkUnit repositoryWorkUnit=new RepositoryWorkUnit(Messages.getString("String_Node_Str")){
              @Override public void run() throws PersistenceException {
                for (                IRepositoryViewObject currentVersion : allVersionToDelete) {
                  repFactory.forceDeleteObjectPhysical(lastVersionBackup,currentVersion.getVersion());
                }
              }
            }
;
            repositoryWorkUnit.setForceTransaction(true);
            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())) {
          Resource resource=ProjectManager.getInstance().getCurrentProject().getEmfProject().eResource();
          if (resource != null && resource.getContents() != null) {
            resource.getContents().add(author);
          }
        }
      }
      beforeCreatingItem(selectedImportItem);
      final RepositoryObjectCache repObjectcache=ImportCacheHelper.getInstance().getRepObjectcache();
      if (lastVersion == null || selectedImportItem.getState().equals(ImportItem.State.ID_EXISTED)) {
        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(e.getMessage());
      logError(e);
    }
  }
}