Program: 126923
Project: 126923
Buggy source:
public void execute(RepositoryNode sourceNode,RepositoryNode targetNode) throws Exception {
  if (!validateAction(sourceNode,targetNode)) {
    return;
  }
  if (targetNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
    targetNode=targetNode.getParent();
  }
  final IPath path=RepositoryNodeUtilities.getPath(targetNode);
  if (sourceNode.getType().equals(ENodeType.REPOSITORY_ELEMENT)) {
    final Item originalItem=sourceNode.getObject().getProperty().getItem();
    List<IRepositoryViewObject> allVersion=factory.getAllVersion(originalItem.getProperty().getId());
    if (allVersion.size() == 1) {
      copySingleVersionItem(originalItem,path);
    }
 else     if (allVersion.size() > 1) {
      PastSelectorDialog dialog=new PastSelectorDialog(Display.getCurrent().getActiveShell(),allVersion,sourceNode);
      if (dialog.open() == Window.OK) {
        final Set<IRepositoryViewObject> selectedVersionItems=dialog.getSelectedVersionItems();
        final IWorkspaceRunnable op=new IWorkspaceRunnable(){
          @Override public void run(          IProgressMonitor monitor) throws CoreException {
            try {
              Iterator<IRepositoryViewObject> iterator=selectedVersionItems.iterator();
              while (iterator.hasNext()) {
                IRepositoryViewObject repObj=iterator.next();
                Item selectedItem=repObj.getProperty().getItem();
                if (!iterator.hasNext() && isHadoopClusterItem(selectedItem)) {
                  copyHadoopClusterItem(selectedItem,path);
                  return;
                }
              }
              String id=null;
              String label=null;
              boolean isfirst=true;
              boolean needSys=true;
              for (              IRepositoryViewObject object : selectedVersionItems) {
                Item selectedItem=object.getProperty().getItem();
                Item copy=null;
                if (isfirst) {
                  copy=factory.copy(selectedItem,path);
                  id=copy.getProperty().getId();
                  label=copy.getProperty().getLabel();
                  isfirst=false;
                }
 else {
                  copy=factory.copy(selectedItem,path,label);
                }
                copy.getProperty().setId(id);
                if (needSys && originalItem instanceof RoutineItem) {
                  String lastestVersion=getLastestVersion(selectedVersionItems);
                  if (lastestVersion.equals(copy.getProperty().getVersion())) {
                    synDuplicatedRoutine((RoutineItem)copy,selectedItem.getProperty().getLabel());
                    needSys=false;
                  }
                }
                if (copy instanceof ProcessItem) {
                  RelationshipItemBuilder.getInstance().addOrUpdateItem(copy);
                }
                factory.save(copy);
              }
            }
 catch (            PersistenceException e) {
              ExceptionHandler.process(e);
            }
catch (            BusinessException e) {
              ExceptionHandler.process(e);
            }
          }
        }
;
        IRunnableWithProgress iRunnableWithProgress=new IRunnableWithProgress(){
          @Override public void run(          IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            IWorkspace workspace=ResourcesPlugin.getWorkspace();
            try {
              ISchedulingRule schedulingRule=workspace.getRoot();
              workspace.run(op,schedulingRule,IWorkspace.AVOID_UPDATE,monitor);
            }
 catch (            CoreException e) {
              throw new InvocationTargetException(e);
            }
          }
        }
;
        try {
          new ProgressMonitorDialog(null).run(true,true,iRunnableWithProgress);
        }
 catch (        InvocationTargetException e) {
          ExceptionHandler.process(e);
        }
catch (        InterruptedException e) {
        }
      }
    }
  }
}

Fixed version (ground truth):
public void execute(RepositoryNode sourceNode,RepositoryNode targetNode) throws Exception {
  if (!validateAction(sourceNode,targetNode)) {
    return;
  }
  if (targetNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
    targetNode=targetNode.getParent();
  }
  final IPath path=RepositoryNodeUtilities.getPath(targetNode);
  if (sourceNode.getType().equals(ENodeType.REPOSITORY_ELEMENT)) {
    final Item originalItem=sourceNode.getObject().getProperty().getItem();
    List<IRepositoryViewObject> allVersion=factory.getAllVersion(originalItem.getProperty().getId());
    if (allVersion.size() == 1) {
      copySingleVersionItem(originalItem,path);
    }
 else     if (allVersion.size() > 1) {
      PastSelectorDialog dialog=new PastSelectorDialog(Display.getCurrent().getActiveShell(),allVersion,sourceNode);
      if (dialog.open() == Window.OK) {
        final Set<IRepositoryViewObject> selectedVersionItems=dialog.getSelectedVersionItems();
        final IWorkspaceRunnable op=new IWorkspaceRunnable(){
          @Override public void run(          IProgressMonitor monitor) throws CoreException {
            try {
              Iterator<IRepositoryViewObject> iterator=selectedVersionItems.iterator();
              while (iterator.hasNext()) {
                IRepositoryViewObject repObj=iterator.next();
                Item selectedItem=repObj.getProperty().getItem();
                if (!iterator.hasNext() && isHadoopClusterItem(selectedItem)) {
                  copyHadoopClusterItem(selectedItem,path);
                  return;
                }
              }
              String id=null;
              String label=null;
              boolean isfirst=true;
              boolean needSys=true;
              List newItems=new ArrayList();
              for (              IRepositoryViewObject object : selectedVersionItems) {
                Item selectedItem=object.getProperty().getItem();
                Item copy=null;
                if (isfirst) {
                  copy=factory.copy(selectedItem,path);
                  id=copy.getProperty().getId();
                  label=copy.getProperty().getLabel();
                  isfirst=false;
                }
 else {
                  copy=factory.copy(selectedItem,path,label);
                }
                copy.getProperty().setId(id);
                if (needSys && originalItem instanceof RoutineItem) {
                  String lastestVersion=getLastestVersion(selectedVersionItems);
                  if (lastestVersion.equals(copy.getProperty().getVersion())) {
                    synDuplicatedRoutine((RoutineItem)copy,selectedItem.getProperty().getLabel());
                    needSys=false;
                  }
                }
                if (copy instanceof ProcessItem) {
                  RelationshipItemBuilder.getInstance().addOrUpdateItem(copy);
                }
                newItems.add(copy);
                factory.save(copy);
              }
              if (newItems.size() > 0) {
                Collections.sort(newItems,new Comparator(){
                  @Override public int compare(                  Object o1,                  Object o2){
                    Item i1=(Item)o1;
                    Item i2=(Item)o2;
                    return i1.getProperty().getVersion().compareTo(i2.getProperty().getVersion());
                  }
                }
);
                Item item=(Item)newItems.get(newItems.size() - 1);
                copyDataServiceRelateJob(item);
              }
            }
 catch (            PersistenceException e) {
              ExceptionHandler.process(e);
            }
catch (            BusinessException e) {
              ExceptionHandler.process(e);
            }
          }
        }
;
        IRunnableWithProgress iRunnableWithProgress=new IRunnableWithProgress(){
          @Override public void run(          IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            IWorkspace workspace=ResourcesPlugin.getWorkspace();
            try {
              ISchedulingRule schedulingRule=workspace.getRoot();
              workspace.run(op,schedulingRule,IWorkspace.AVOID_UPDATE,monitor);
            }
 catch (            CoreException e) {
              throw new InvocationTargetException(e);
            }
          }
        }
;
        try {
          new ProgressMonitorDialog(null).run(false,false,iRunnableWithProgress);
        }
 catch (        InvocationTargetException e) {
          ExceptionHandler.process(e);
        }
catch (        InterruptedException e) {
        }
      }
    }
  }
}