Program: 128639
Project: 128639
Buggy source:
private boolean deleteElements(IProxyRepositoryFactory factory,DeleteActionCache deleteActionCache,final RepositoryNode currentJobNode,Boolean confirm) throws PersistenceException, BusinessException {
  boolean needReturn=false;
  final boolean[] enableDeleting=new boolean[1];
  enableDeleting[0]=true;
  final IRepositoryViewObject objToDelete=currentJobNode.getObject();
  final List<JobletReferenceBean> checkRepository=checkRepositoryNodeFromProcess(factory,deleteActionCache,currentJobNode);
  if (checkRepository.size() > 0) {
    Display.getDefault().syncExec(new Runnable(){
      public void run(){
        JobletReferenceDialog dialog=new JobletReferenceDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),objToDelete,checkRepository);
        dialog.open();
      }
    }
);
    enableDeleting[0]=false;
    return true;
  }
  final List<ContextReferenceBean> checkContext=checkContextFromProcess(factory,deleteActionCache,currentJobNode);
  if (checkContext.size() > 0) {
    Display.getDefault().syncExec(new Runnable(){
      public void run(){
        ContextReferenceDialog dialog=new ContextReferenceDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),objToDelete,checkContext);
        int returnCode=dialog.open();
switch (returnCode) {
case Window.OK:
          enableDeleting[0]=true;
        break;
case Window.CANCEL:
      enableDeleting[0]=false;
    break;
}
}
}
);
}
if (!enableDeleting[0]) {
return true;
}
Item item=null;
if (objToDelete != null && objToDelete.getProperty() != null) {
item=objToDelete.getProperty().getItem();
}
AbstractResourceChangesService resChangeService=TDQServiceRegister.getInstance().getResourceChangeService(AbstractResourceChangesService.class);
if (resChangeService != null && item != null && item instanceof ConnectionItem && item.getState().isDeleted()) {
if (!resChangeService.handleResourceChange(((ConnectionItem)item).getConnection())) {
return true;
}
}
ERepositoryObjectType nodeType=(ERepositoryObjectType)currentJobNode.getProperties(EProperties.CONTENT_TYPE);
if (nodeType != null && nodeType.isSubItem()) {
Display.getDefault().syncExec(new Runnable(){
public void run(){
final DeleteTableAction deleteTableAction=new DeleteTableAction();
deleteTableAction.setWorkbenchPart(getWorkbenchPart());
deleteTableAction.run();
}
}
);
needReturn=true;
}
 else {
if (factory.getStatus(objToDelete) == ERepositoryStatus.DELETED) {
if (confirm == null) {
Display.getDefault().syncExec(new Runnable(){
  public void run(){
    String title=Messages.getString("String_Node_Str");
    String message=currentJobNode.getProperties(EProperties.LABEL) + "String_Node_Str" + Messages.getString("String_Node_Str")+ "String_Node_Str"+ Messages.getString("String_Node_Str");
    confirmFromDialog=MessageDialog.openQuestion(new Shell(),title,message);
  }
}
);
confirm=confirmFromDialog;
}
if (confirm) {
deleteActionCache.closeOpenedEditor(objToDelete);
if (currentJobNode.getType() == ENodeType.SIMPLE_FOLDER) {
  boolean success=true;
  for (  IRepositoryNode curNode : currentJobNode.getChildren()) {
    try {
      deleteElements(factory,deleteActionCache,(RepositoryNode)curNode,confirm);
    }
 catch (    Exception e) {
      ExceptionHandler.process(e);
      success=false;
    }
  }
  if (success) {
    if (currentJobNode.getObject() != null && currentJobNode.getObject().getProperty() != null && currentJobNode.getObject().getProperty().getItem() != null) {
      Item fitem=currentJobNode.getObject().getProperty().getItem();
      if ((fitem instanceof FolderItem) && (((FolderItem)fitem).getType().getValue() == FolderType.FOLDER)) {
        factory.deleteFolder(currentJobNode.getContentType(),RepositoryNodeUtilities.getFolderPath(currentJobNode.getObject().getProperty().getItem()));
      }
 else {
        factory.deleteFolder(currentJobNode.getContentType(),RepositoryNodeUtilities.getPath(currentJobNode));
      }
    }
 else {
      factory.deleteFolder(currentJobNode.getContentType(),RepositoryNodeUtilities.getPath(currentJobNode));
    }
  }
}
 else {
  if (resChangeService != null && (item instanceof TDQItem || item instanceof ConnectionItem)) {
    resChangeService.removeAllDependecies(item);
  }
  factory.deleteObjectPhysical(objToDelete);
  ExpressionPersistance.getInstance().jobDeleted(objToDelete.getLabel());
}
}
}
 else {
factory.deleteObjectLogical(objToDelete);
updateRelatedViews();
removeConnFromSQLExplorer(repositoryNode);
}
}
return needReturn;
}

Fixed version (ground truth):
private boolean deleteElements(IProxyRepositoryFactory factory,DeleteActionCache deleteActionCache,final RepositoryNode currentJobNode,Boolean confirm) throws PersistenceException, BusinessException {
  boolean needReturn=false;
  final boolean[] enableDeleting=new boolean[1];
  enableDeleting[0]=true;
  final IRepositoryViewObject objToDelete=currentJobNode.getObject();
  final List<JobletReferenceBean> checkRepository=checkRepositoryNodeFromProcess(factory,deleteActionCache,currentJobNode);
  if (checkRepository.size() > 0) {
    Display.getDefault().syncExec(new Runnable(){
      public void run(){
        JobletReferenceDialog dialog=new JobletReferenceDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),objToDelete,checkRepository);
        dialog.open();
      }
    }
);
    enableDeleting[0]=false;
    return true;
  }
  final List<ContextReferenceBean> checkContext=checkContextFromProcess(factory,deleteActionCache,currentJobNode);
  if (checkContext.size() > 0) {
    Display.getDefault().syncExec(new Runnable(){
      public void run(){
        ContextReferenceDialog dialog=new ContextReferenceDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),objToDelete,checkContext);
        int returnCode=dialog.open();
switch (returnCode) {
case Window.OK:
          enableDeleting[0]=true;
        break;
case Window.CANCEL:
      enableDeleting[0]=false;
    break;
}
}
}
);
}
if (!enableDeleting[0]) {
return true;
}
Item item=null;
if (objToDelete != null && objToDelete.getProperty() != null) {
item=objToDelete.getProperty().getItem();
}
AbstractResourceChangesService resChangeService=TDQServiceRegister.getInstance().getResourceChangeService(AbstractResourceChangesService.class);
if (resChangeService != null && item != null && item instanceof ConnectionItem && item.getState().isDeleted()) {
if (!resChangeService.handleResourceChange(((ConnectionItem)item).getConnection())) {
return true;
}
}
ERepositoryObjectType nodeType=(ERepositoryObjectType)currentJobNode.getProperties(EProperties.CONTENT_TYPE);
if (nodeType != null && nodeType.isSubItem()) {
Display.getDefault().syncExec(new Runnable(){
public void run(){
final DeleteTableAction deleteTableAction=new DeleteTableAction();
deleteTableAction.setWorkbenchPart(getWorkbenchPart());
deleteTableAction.run();
}
}
);
needReturn=true;
}
 else {
if (factory.getStatus(objToDelete) == ERepositoryStatus.DELETED) {
if (confirm == null) {
Display.getDefault().syncExec(new Runnable(){
  public void run(){
    String title=Messages.getString("String_Node_Str");
    String message=currentJobNode.getProperties(EProperties.LABEL) + "String_Node_Str" + Messages.getString("String_Node_Str")+ "String_Node_Str"+ Messages.getString("String_Node_Str");
    confirmFromDialog=MessageDialog.openQuestion(new Shell(),title,message);
  }
}
);
confirm=confirmFromDialog;
}
if (confirm) {
deleteActionCache.closeOpenedEditor(objToDelete);
if (currentJobNode.getType() == ENodeType.SIMPLE_FOLDER) {
  boolean success=true;
  for (  IRepositoryNode curNode : currentJobNode.getChildren()) {
    try {
      deleteElements(factory,deleteActionCache,(RepositoryNode)curNode,confirm);
    }
 catch (    Exception e) {
      ExceptionHandler.process(e);
      success=false;
    }
  }
  if (success) {
    if (currentJobNode.getObject() != null && currentJobNode.getObject().getProperty() != null && currentJobNode.getObject().getProperty().getItem() != null) {
      Item fitem=currentJobNode.getObject().getProperty().getItem();
      if ((fitem instanceof FolderItem) && (((FolderItem)fitem).getType().getValue() == FolderType.FOLDER)) {
        factory.deleteFolder(currentJobNode.getContentType(),RepositoryNodeUtilities.getFolderPath(currentJobNode.getObject().getProperty().getItem()));
      }
 else {
        factory.deleteFolder(currentJobNode.getContentType(),RepositoryNodeUtilities.getPath(currentJobNode));
      }
    }
 else {
      factory.deleteFolder(currentJobNode.getContentType(),RepositoryNodeUtilities.getPath(currentJobNode));
    }
  }
}
 else {
  if (resChangeService != null && (item instanceof TDQItem || item instanceof ConnectionItem)) {
    resChangeService.removeAllDependecies(item);
  }
  factory.deleteObjectPhysical(objToDelete);
  ExpressionPersistance.getInstance().jobDeleted(objToDelete.getLabel());
}
}
}
 else {
factory.deleteObjectLogical(objToDelete);
updateRelatedViews();
removeConnFromSQLExplorer(currentJobNode);
}
}
return needReturn;
}