Program: 126577
Project: 126577
Buggy source:
public void importItemRecords(final IProgressMonitor progressMonitor,final ResourcesManager resManager,final List<ImportItem> checkedItemRecords,final boolean overwrite,final ImportItem[] allImportItemRecords,final IPath destinationPath) throws InvocationTargetException {
  TimeMeasure.display=CommonsPlugin.isDebugMode();
  TimeMeasure.displaySteps=CommonsPlugin.isDebugMode();
  TimeMeasure.measureActive=CommonsPlugin.isDebugMode();
  TimeMeasure.begin("String_Node_Str");
  ImportCacheHelper importCacheHelper=ImportCacheHelper.getInstance();
  try {
    importCacheHelper.beforeImportItems();
    if (resManager == null || checkedItemRecords.isEmpty()) {
      return;
    }
    progressMonitor.beginTask(Messages.getString("String_Node_Str"),checkedItemRecords.size() * 2 + 1);
    RepositoryWorkUnit repositoryWorkUnit=new RepositoryWorkUnit(Messages.getString("String_Node_Str")){
      @Override public void run() throws PersistenceException {
        final IWorkspaceRunnable op=new IWorkspaceRunnable(){
          @Override public void run(          final IProgressMonitor monitor) throws CoreException {
            preImport(monitor,resManager,checkedItemRecords.toArray(new ImportItem[0]),allImportItemRecords);
            final Set<String> overwriteDeletedItems=new HashSet<String>();
            final Set<String> idDeletedBeforeImport=new HashSet<String>();
            Map<String,String> nameToIdMap=new HashMap<String,String>();
            for (            ImportItem itemRecord : checkedItemRecords) {
              if (monitor.isCanceled()) {
                return;
              }
              if (itemRecord.isValid()) {
                if (itemRecord.getState() == State.ID_EXISTED) {
                  String id=nameToIdMap.get(itemRecord.getProperty().getLabel() + ERepositoryObjectType.getItemType(itemRecord.getProperty().getItem()).toString());
                  if (id == null) {
                    id=EcoreUtil.generateUUID();
                    nameToIdMap.put(itemRecord.getProperty().getLabel() + ERepositoryObjectType.getItemType(itemRecord.getProperty().getItem()).toString(),id);
                  }
                  itemRecord.getProperty().setId(id);
                }
              }
            }
            try {
              importItemRecordsWithRelations(monitor,resManager,checkedItemRecords,overwrite,allImportItemRecords,destinationPath,overwriteDeletedItems,idDeletedBeforeImport);
            }
 catch (            Exception e) {
              throw new CoreException(new Status(IStatus.ERROR,FrameworkUtil.getBundle(this.getClass()).getSymbolicName(),Messages.getString("String_Node_Str"),e));
            }
            if (PluginChecker.isJobLetPluginLoaded()) {
              IJobletProviderService service=(IJobletProviderService)GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
              if (service != null) {
                service.loadComponentsFromProviders();
              }
            }
            ImportCacheHelper.getInstance().checkDeletedFolders();
            monitor.done();
            TimeMeasure.step("String_Node_Str","String_Node_Str");
            if (RelationshipItemBuilder.getInstance().isNeedSaveRelations()) {
              RelationshipItemBuilder.getInstance().saveRelations();
              TimeMeasure.step("String_Node_Str","String_Node_Str");
            }
 else {
              try {
                final IProxyRepositoryFactory factory=CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
                factory.saveProject(ProjectManager.getInstance().getCurrentProject());
              }
 catch (              PersistenceException e) {
                throw new CoreException(new Status(IStatus.ERROR,FrameworkUtil.getBundle(this.getClass()).getSymbolicName(),Messages.getString("String_Node_Str"),e));
              }
              TimeMeasure.step("String_Node_Str","String_Node_Str");
            }
            List<ImportItem> importedItemRecords=ImportCacheHelper.getInstance().getImportedItemRecords();
            postImport(monitor,resManager,importedItemRecords.toArray(new ImportItem[0]));
          }
          private void importItemRecordsWithRelations(          final IProgressMonitor monitor,          final ResourcesManager manager,          final List<ImportItem> processingItemRecords,          final boolean overwriting,          ImportItem[] allPopulatedImportItemRecords,          IPath destinationPath,          final Set<String> overwriteDeletedItems,          final Set<String> idDeletedBeforeImport) throws Exception {
            for (            ImportItem itemRecord : processingItemRecords) {
              if (monitor.isCanceled()) {
                return;
              }
              if (itemRecord.isImported()) {
                return;
              }
              final IImportItemsHandler importHandler=itemRecord.getImportHandler();
              if (importHandler != null && itemRecord.isValid()) {
                List<ImportItem> relatedItemRecord=importHandler.findRelatedImportItems(monitor,manager,itemRecord,allPopulatedImportItemRecords);
                if (importHandler.isPriorImportRelatedItem()) {
                  if (!relatedItemRecord.isEmpty()) {
                    importItemRecordsWithRelations(monitor,manager,relatedItemRecord,overwriting,allPopulatedImportItemRecords,destinationPath,overwriteDeletedItems,idDeletedBeforeImport);
                  }
                }
                if (monitor.isCanceled()) {
                  return;
                }
                importHandler.doImport(monitor,manager,itemRecord,overwriting,destinationPath,overwriteDeletedItems,idDeletedBeforeImport);
                if (monitor.isCanceled()) {
                  return;
                }
                if (!importHandler.isPriorImportRelatedItem()) {
                  if (!relatedItemRecord.isEmpty()) {
                    importItemRecordsWithRelations(monitor,manager,relatedItemRecord,overwriting,allPopulatedImportItemRecords,destinationPath,overwriteDeletedItems,idDeletedBeforeImport);
                  }
                }
                importHandler.afterImportingItems(monitor,manager,itemRecord);
                ImportCacheHelper.getInstance().getImportedItemRecords().add(itemRecord);
                monitor.worked(1);
              }
            }
          }
        }
;
        IWorkspace workspace=ResourcesPlugin.getWorkspace();
        try {
          ISchedulingRule schedulingRule=workspace.getRoot();
          workspace.run(op,schedulingRule,IWorkspace.AVOID_UPDATE,progressMonitor);
        }
 catch (        CoreException e) {
        }
      }
    }
;
    repositoryWorkUnit.setAvoidUnloadResources(true);
    repositoryWorkUnit.setUnloadResourcesAfterRun(true);
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
    progressMonitor.done();
    if (ImportCacheHelper.getInstance().hasImportingError()) {
      throw new InvocationTargetException(new CoreException(new Status(IStatus.ERROR,FrameworkUtil.getBundle(this.getClass()).getSymbolicName(),Messages.getString("String_Node_Str"))));
    }
  }
  finally {
    importCacheHelper.afterImportItems();
    TimeMeasure.end("String_Node_Str");
    TimeMeasure.display=false;
    TimeMeasure.displaySteps=false;
    TimeMeasure.measureActive=false;
  }
}

Fixed version (ground truth):
public void importItemRecords(final IProgressMonitor progressMonitor,final ResourcesManager resManager,final List<ImportItem> checkedItemRecords,final boolean overwrite,final ImportItem[] allImportItemRecords,final IPath destinationPath) throws InvocationTargetException {
  TimeMeasure.display=CommonsPlugin.isDebugMode();
  TimeMeasure.displaySteps=CommonsPlugin.isDebugMode();
  TimeMeasure.measureActive=CommonsPlugin.isDebugMode();
  TimeMeasure.begin("String_Node_Str");
  ImportCacheHelper importCacheHelper=ImportCacheHelper.getInstance();
  try {
    importCacheHelper.beforeImportItems();
    if (resManager == null || checkedItemRecords.isEmpty()) {
      return;
    }
    progressMonitor.beginTask(Messages.getString("String_Node_Str"),checkedItemRecords.size() * 2 + 1);
    RepositoryWorkUnit repositoryWorkUnit=new RepositoryWorkUnit(Messages.getString("String_Node_Str")){
      @Override public void run() throws PersistenceException {
        final IWorkspaceRunnable op=new IWorkspaceRunnable(){
          @Override public void run(          final IProgressMonitor monitor) throws CoreException {
            preImport(monitor,resManager,checkedItemRecords.toArray(new ImportItem[0]),allImportItemRecords);
            final Set<String> overwriteDeletedItems=new HashSet<String>();
            final Set<String> idDeletedBeforeImport=new HashSet<String>();
            Map<String,String> nameToIdMap=new HashMap<String,String>();
            for (            ImportItem itemRecord : checkedItemRecords) {
              if (monitor.isCanceled()) {
                return;
              }
              if (itemRecord.isValid()) {
                if (itemRecord.getState() == State.ID_EXISTED) {
                  String id=nameToIdMap.get(itemRecord.getProperty().getLabel() + ERepositoryObjectType.getItemType(itemRecord.getProperty().getItem()).toString());
                  if (id == null) {
                    id=EcoreUtil.generateUUID();
                    nameToIdMap.put(itemRecord.getProperty().getLabel() + ERepositoryObjectType.getItemType(itemRecord.getProperty().getItem()).toString(),id);
                  }
                  itemRecord.getProperty().setId(id);
                }
              }
            }
            try {
              importItemRecordsWithRelations(monitor,resManager,checkedItemRecords,overwrite,allImportItemRecords,destinationPath,overwriteDeletedItems,idDeletedBeforeImport);
            }
 catch (            Exception e) {
              if (Platform.inDebugMode()) {
                ExceptionHandler.process(e);
              }
              throw new CoreException(new Status(IStatus.ERROR,FrameworkUtil.getBundle(this.getClass()).getSymbolicName(),Messages.getString("String_Node_Str"),e));
            }
            if (PluginChecker.isJobLetPluginLoaded()) {
              IJobletProviderService service=(IJobletProviderService)GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
              if (service != null) {
                service.loadComponentsFromProviders();
              }
            }
            ImportCacheHelper.getInstance().checkDeletedFolders();
            monitor.done();
            TimeMeasure.step("String_Node_Str","String_Node_Str");
            if (RelationshipItemBuilder.getInstance().isNeedSaveRelations()) {
              RelationshipItemBuilder.getInstance().saveRelations();
              TimeMeasure.step("String_Node_Str","String_Node_Str");
            }
 else {
              try {
                final IProxyRepositoryFactory factory=CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
                factory.saveProject(ProjectManager.getInstance().getCurrentProject());
              }
 catch (              PersistenceException e) {
                if (Platform.inDebugMode()) {
                  ExceptionHandler.process(e);
                }
                throw new CoreException(new Status(IStatus.ERROR,FrameworkUtil.getBundle(this.getClass()).getSymbolicName(),Messages.getString("String_Node_Str"),e));
              }
              TimeMeasure.step("String_Node_Str","String_Node_Str");
            }
            List<ImportItem> importedItemRecords=ImportCacheHelper.getInstance().getImportedItemRecords();
            postImport(monitor,resManager,importedItemRecords.toArray(new ImportItem[0]));
          }
          private void importItemRecordsWithRelations(          final IProgressMonitor monitor,          final ResourcesManager manager,          final List<ImportItem> processingItemRecords,          final boolean overwriting,          ImportItem[] allPopulatedImportItemRecords,          IPath destinationPath,          final Set<String> overwriteDeletedItems,          final Set<String> idDeletedBeforeImport) throws Exception {
            for (            ImportItem itemRecord : processingItemRecords) {
              if (monitor.isCanceled()) {
                return;
              }
              if (itemRecord.isImported()) {
                return;
              }
              try {
                final IImportItemsHandler importHandler=itemRecord.getImportHandler();
                if (importHandler != null && itemRecord.isValid()) {
                  List<ImportItem> relatedItemRecord=importHandler.findRelatedImportItems(monitor,manager,itemRecord,allPopulatedImportItemRecords);
                  if (importHandler.isPriorImportRelatedItem()) {
                    if (!relatedItemRecord.isEmpty()) {
                      importItemRecordsWithRelations(monitor,manager,relatedItemRecord,overwriting,allPopulatedImportItemRecords,destinationPath,overwriteDeletedItems,idDeletedBeforeImport);
                    }
                  }
                  if (monitor.isCanceled()) {
                    return;
                  }
                  importHandler.doImport(monitor,manager,itemRecord,overwriting,destinationPath,overwriteDeletedItems,idDeletedBeforeImport);
                  if (monitor.isCanceled()) {
                    return;
                  }
                  if (!importHandler.isPriorImportRelatedItem()) {
                    if (!relatedItemRecord.isEmpty()) {
                      importItemRecordsWithRelations(monitor,manager,relatedItemRecord,overwriting,allPopulatedImportItemRecords,destinationPath,overwriteDeletedItems,idDeletedBeforeImport);
                    }
                  }
                  importHandler.afterImportingItems(monitor,manager,itemRecord);
                  ImportCacheHelper.getInstance().getImportedItemRecords().add(itemRecord);
                  monitor.worked(1);
                }
              }
 catch (              Exception e) {
                if (Platform.inDebugMode()) {
                  itemRecord.addError(e.getMessage());
                  ImportCacheHelper.getInstance().setImportingError(true);
                  ExceptionHandler.process(e);
                }
              }
            }
          }
        }
;
        IWorkspace workspace=ResourcesPlugin.getWorkspace();
        try {
          ISchedulingRule schedulingRule=workspace.getRoot();
          workspace.run(op,schedulingRule,IWorkspace.AVOID_UPDATE,progressMonitor);
        }
 catch (        CoreException e) {
          if (Platform.inDebugMode()) {
            ExceptionHandler.process(e);
          }
        }
      }
    }
;
    repositoryWorkUnit.setAvoidUnloadResources(true);
    repositoryWorkUnit.setUnloadResourcesAfterRun(true);
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
    progressMonitor.done();
    if (ImportCacheHelper.getInstance().hasImportingError()) {
      throw new InvocationTargetException(new CoreException(new Status(IStatus.ERROR,FrameworkUtil.getBundle(this.getClass()).getSymbolicName(),Messages.getString("String_Node_Str"))));
    }
  }
  finally {
    importCacheHelper.afterImportItems();
    TimeMeasure.end("String_Node_Str");
    TimeMeasure.display=false;
    TimeMeasure.displaySteps=false;
    TimeMeasure.measureActive=false;
  }
}