Program: 125480
Project: 125480
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");
  final List<EmptyFolderImportItem> checkedFolders=new ArrayList<EmptyFolderImportItem>();
  for (  ImportItem importItem : checkedItemRecords) {
    if (importItem instanceof EmptyFolderImportItem) {
      checkedFolders.add((EmptyFolderImportItem)importItem);
    }
  }
  checkedItemRecords.removeAll(checkedFolders);
  final List<IImportItemsHandler> importItemHandlersList=new ArrayList<IImportItemsHandler>(Arrays.asList(getImportHandlers()));
  Collections.sort(checkedItemRecords,new Comparator<ImportItem>(){
    @Override public int compare(    ImportItem o1,    ImportItem o2){
      IImportItemsHandler importHandler1=o1.getImportHandler();
      IImportItemsHandler importHandler2=o2.getImportHandler();
      if (importHandler1 != null && importHandler2 != null) {
        int index1=importItemHandlersList.indexOf(importHandler1);
        int index2=importItemHandlersList.indexOf(importHandler2);
        if (index1 > -1 && index2 > -1) {
          return index1 - index2;
        }
      }
      return 0;
    }
  }
);
  ImportCacheHelper importCacheHelper=ImportCacheHelper.getInstance();
  try {
    importCacheHelper.beforeImportItems();
    if (resManager == null || checkedItemRecords.isEmpty() && checkedFolders.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 IProxyRepositoryFactory factory=CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
            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();
            ImportCacheHelper.getInstance().checkDeletedItems();
            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 {
                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");
            }
            if (!checkedFolders.isEmpty()) {
              for (              EmptyFolderImportItem folder : checkedFolders) {
                boolean exist=false;
                ERepositoryObjectType repositoryType=folder.getRepositoryType();
                IPath path=folder.getPath();
                if (destinationPath != null) {
                  IPath desPath=destinationPath.makeRelativeTo(new Path(repositoryType.getFolder()));
                  path=desPath.append(folder.getPath());
                }
                String label=folder.getLabel();
                FolderItem getFolderItem=factory.getFolderItem(ProjectManager.getInstance().getCurrentProject(),repositoryType,path);
                if (getFolderItem != null) {
                  for (                  Object obj : getFolderItem.getChildren()) {
                    if (obj instanceof FolderItem) {
                      FolderItem existFolder=(FolderItem)obj;
                      if (label.equals(existFolder.getProperty().getLabel())) {
                        exist=true;
                        break;
                      }
                    }
                  }
                }
                if (!exist) {
                  try {
                    factory.createFolder(repositoryType,path,label);
                  }
 catch (                  PersistenceException e) {
                    ExceptionHandler.process(e);
                  }
                }
              }
            }
            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 {
            boolean hasJoblet=false;
            boolean reloadJoblet=false;
            for (            ImportItem itemRecord : processingItemRecords) {
              if (monitor.isCanceled()) {
                return;
              }
              if (itemRecord.isImported()) {
                continue;
              }
              if (ERepositoryObjectType.JOBLET == itemRecord.getRepositoryType()) {
                hasJoblet=true;
              }
              if (hasJoblet) {
                if (ERepositoryObjectType.JOBLET != itemRecord.getRepositoryType()) {
                  reloadJoblet=true;
                  if (PluginChecker.isJobLetPluginLoaded()) {
                    IJobletProviderService jobletService=(IJobletProviderService)GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                    if (jobletService != null) {
                      jobletService.loadComponentsFromProviders();
                    }
                  }
                }
              }
              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);
                }
              }
            }
            if (hasJoblet && !reloadJoblet && PluginChecker.isJobLetPluginLoaded()) {
              IJobletProviderService jobletService=(IJobletProviderService)GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
              if (jobletService != null) {
                jobletService.loadComponentsFromProviders();
              }
            }
          }
        }
;
        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;
  }
}

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");
  final List<EmptyFolderImportItem> checkedFolders=new ArrayList<EmptyFolderImportItem>();
  for (  ImportItem importItem : checkedItemRecords) {
    if (importItem instanceof EmptyFolderImportItem) {
      checkedFolders.add((EmptyFolderImportItem)importItem);
    }
  }
  checkedItemRecords.removeAll(checkedFolders);
  final List<IImportItemsHandler> importItemHandlersList=new ArrayList<IImportItemsHandler>(Arrays.asList(getImportHandlers()));
  Collections.sort(checkedItemRecords,new Comparator<ImportItem>(){
    @Override public int compare(    ImportItem o1,    ImportItem o2){
      IImportItemsHandler importHandler1=o1.getImportHandler();
      IImportItemsHandler importHandler2=o2.getImportHandler();
      if (importHandler1 != null && importHandler2 != null) {
        int index1=importItemHandlersList.indexOf(importHandler1);
        int index2=importItemHandlersList.indexOf(importHandler2);
        if (index1 > -1 && index2 > -1) {
          return index1 - index2;
        }
      }
      return 0;
    }
  }
);
  ImportCacheHelper importCacheHelper=ImportCacheHelper.getInstance();
  try {
    importCacheHelper.beforeImportItems();
    if (resManager == null || checkedItemRecords.isEmpty() && checkedFolders.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 IProxyRepositoryFactory factory=CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
            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();
            ImportCacheHelper.getInstance().checkDeletedItems();
            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 {
                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");
            }
            if (!checkedFolders.isEmpty()) {
              for (              EmptyFolderImportItem folder : checkedFolders) {
                boolean exist=false;
                ERepositoryObjectType repositoryType=folder.getRepositoryType();
                IPath path=folder.getPath();
                if (destinationPath != null) {
                  IPath desPath=destinationPath.makeRelativeTo(new Path(repositoryType.getFolder()));
                  path=desPath.append(folder.getPath());
                }
                String label=folder.getLabel();
                FolderItem getFolderItem=factory.getFolderItem(ProjectManager.getInstance().getCurrentProject(),repositoryType,path);
                if (getFolderItem != null) {
                  for (                  Object obj : getFolderItem.getChildren()) {
                    if (obj instanceof FolderItem) {
                      FolderItem existFolder=(FolderItem)obj;
                      if (label.equals(existFolder.getProperty().getLabel())) {
                        exist=true;
                        break;
                      }
                    }
                  }
                }
                if (!exist) {
                  try {
                    factory.createFolder(repositoryType,path,label);
                  }
 catch (                  PersistenceException e) {
                    ExceptionHandler.process(e);
                  }
                }
              }
            }
            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 {
            boolean hasJoblet=false;
            boolean reloadJoblet=false;
            for (            ImportItem itemRecord : processingItemRecords) {
              if (monitor.isCanceled()) {
                return;
              }
              if (itemRecord.isImported()) {
                continue;
              }
              if ((ERepositoryObjectType.JOBLET == itemRecord.getRepositoryType()) || (ERepositoryObjectType.SPARK_JOBLET == itemRecord.getRepositoryType()) || (ERepositoryObjectType.SPARK_STREAMING_JOBLET == itemRecord.getRepositoryType())) {
                hasJoblet=true;
              }
              if (hasJoblet) {
                if (ERepositoryObjectType.JOBLET != itemRecord.getRepositoryType() && ERepositoryObjectType.SPARK_JOBLET != itemRecord.getRepositoryType() && ERepositoryObjectType.SPARK_STREAMING_JOBLET != itemRecord.getRepositoryType()) {
                  reloadJoblet=true;
                  if (PluginChecker.isJobLetPluginLoaded()) {
                    IJobletProviderService jobletService=(IJobletProviderService)GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                    if (jobletService != null) {
                      jobletService.loadComponentsFromProviders();
                    }
                  }
                }
              }
              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);
                }
              }
            }
            if (hasJoblet && !reloadJoblet && PluginChecker.isJobLetPluginLoaded()) {
              IJobletProviderService jobletService=(IJobletProviderService)GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
              if (jobletService != null) {
                jobletService.loadComponentsFromProviders();
              }
            }
          }
        }
;
        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;
  }
}