Program: 129508
Project: 129508
Buggy source:
private void addItemToRecycleBin(RepositoryNode parentNode,Item item,List<RepositoryNode> foldersList){
  if (isGeneratedJobItem(item)) {
    return;
  }
  ERepositoryObjectType itemType=ERepositoryObjectType.getItemType(item);
  RepositoryNode currentParentNode=parentNode;
  if (item instanceof FolderItem) {
    itemType=getFolderContentType((FolderItem)item);
    if (itemType == null) {
      return;
    }
    if (itemType != null && itemType.isDQItemType() && !itemType.isSharedType()) {
      return;
    }
    if (item.getState().isDeleted()) {
      Folder folder=new Folder(item.getProperty(),itemType);
      RepositoryNode folderNode=null;
      for (      RepositoryNode existingFolder : foldersList) {
        if (existingFolder.getContentType() == null) {
          break;
        }
        if (existingFolder.getContentType().equals(folder.getRepositoryObjectType()) && existingFolder.getProperties(EProperties.LABEL).equals(folder.getLabel())) {
          folderNode=existingFolder;
          break;
        }
      }
      if (folderNode == null) {
        folderNode=new RepositoryNode(folder,parentNode,ENodeType.SIMPLE_FOLDER);
        folderNode.setProperties(EProperties.CONTENT_TYPE,itemType);
        folderNode.setProperties(EProperties.LABEL,folder.getLabel());
        foldersList.add(folderNode);
        parentNode.getChildren().add(folderNode);
        folderNode.setParent(parentNode);
      }
      for (      Item curItem : (List<Item>)new ArrayList(((FolderItem)item).getChildren())) {
        addItemToRecycleBin(folderNode,curItem,foldersList);
      }
      currentParentNode=folderNode;
    }
 else {
      for (      Item curItem : (List<Item>)new ArrayList(((FolderItem)item).getChildren())) {
        addItemToRecycleBin(parentNode,curItem,foldersList);
      }
    }
  }
 else   if (item.getState() != null && item.getState().isDeleted()) {
    try {
      if (item.getProperty().getVersion().equals(ProxyRepositoryFactory.getInstance().getLastVersion(item.getProperty().getId()).getVersion())) {
        RepositoryNode repNode=new RepositoryNode(new RepositoryViewObject(item.getProperty()),currentParentNode,ENodeType.REPOSITORY_ELEMENT);
        repNode.setProperties(EProperties.CONTENT_TYPE,itemType);
        repNode.setProperties(EProperties.LABEL,item.getProperty().getLabel());
        currentParentNode.getChildren().add(repNode);
        repNode.setParent(currentParentNode);
      }
    }
 catch (    PersistenceException e) {
      ExceptionHandler.process(e);
    }
  }
 else {
    if (item instanceof ConnectionItem) {
      Connection connection=((ConnectionItem)item).getConnection();
      if (connection instanceof SAPConnection) {
        SAPConnection sapConnection=(SAPConnection)connection;
        EList<SAPFunctionUnit> funtions=sapConnection.getFuntions();
        if (funtions != null) {
          for (int i=0; i < funtions.size(); i++) {
            SAPFunctionUnit unit=funtions.get(i);
            if (SubItemHelper.isDeleted(unit)) {
              RepositoryNode tableNode=createSAPNode(new RepositoryViewObject(item.getProperty()),currentParentNode,unit);
              currentParentNode.getChildren().add(tableNode);
              tableNode.setParent(currentParentNode);
            }
 else {
              for (              MetadataTable table : ConnectionHelper.getTables(connection,unit)) {
                if (SubItemHelper.isDeleted(table)) {
                  RepositoryNode tableNode=createMetatableNode(currentParentNode,new RepositoryViewObject(item.getProperty()),table,ERepositoryObjectType.METADATA_CON_TABLE);
                  currentParentNode.getChildren().add(tableNode);
                  tableNode.setParent(currentParentNode);
                }
              }
            }
          }
        }
        EList<SAPIDocUnit> iDocs=sapConnection.getIDocs();
        if (iDocs != null) {
          for (int i=0; i < iDocs.size(); i++) {
            SAPIDocUnit unit=iDocs.get(i);
            if (SubItemHelper.isDeleted(unit)) {
              RepositoryNode tableNode=createSAPNode(new RepositoryViewObject(item.getProperty()),currentParentNode,unit);
              currentParentNode.getChildren().add(tableNode);
              tableNode.setParent(currentParentNode);
            }
          }
        }
        return;
      }
      for (      MetadataTable table : ConnectionHelper.getTables(connection)) {
        if (SubItemHelper.isDeleted(table)) {
          RepositoryNode tableNode=createMetatableNode(currentParentNode,new RepositoryViewObject(item.getProperty()),table,ERepositoryObjectType.METADATA_CON_TABLE);
          currentParentNode.getChildren().add(tableNode);
          tableNode.setParent(currentParentNode);
        }
      }
      QueriesConnection queriesConnection=connection.getQueries();
      if (queriesConnection != null) {
        for (        Query query : queriesConnection.getQuery()) {
          if (SubItemHelper.isDeleted(query)) {
            RepositoryNode queryNode=createQueryNode(currentParentNode,new RepositoryViewObject(item.getProperty()),query);
            currentParentNode.getChildren().add(queryNode);
            queryNode.setParent(currentParentNode);
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
private void addItemToRecycleBin(RepositoryNode parentNode,Item item,List<RepositoryNode> foldersList){
  if (isGeneratedJobItem(item)) {
    return;
  }
  ERepositoryObjectType itemType=ERepositoryObjectType.getItemType(item);
  RepositoryNode currentParentNode=parentNode;
  if (item instanceof FolderItem) {
    itemType=getFolderContentType((FolderItem)item);
    if (itemType == null) {
      return;
    }
    if (itemType != null && itemType.isDQItemType() && !itemType.isSharedType()) {
      return;
    }
    if (item.getState().isDeleted()) {
      Folder folder=new Folder(item.getProperty(),itemType);
      RepositoryNode folderNode=null;
      for (      RepositoryNode existingFolder : foldersList) {
        if (existingFolder.getContentType() == null) {
          break;
        }
        if (existingFolder.getContentType().equals(folder.getRepositoryObjectType()) && existingFolder.getProperties(EProperties.LABEL).equals(folder.getLabel())) {
          folderNode=existingFolder;
          break;
        }
      }
      if (folderNode == null) {
        folderNode=new RepositoryNode(folder,parentNode,ENodeType.SIMPLE_FOLDER);
        folderNode.setProperties(EProperties.CONTENT_TYPE,itemType);
        folderNode.setProperties(EProperties.LABEL,folder.getLabel());
        foldersList.add(folderNode);
        parentNode.getChildren().add(folderNode);
        folderNode.setParent(parentNode);
      }
      for (      Item curItem : (List<Item>)new ArrayList(((FolderItem)item).getChildren())) {
        addItemToRecycleBin(folderNode,curItem,foldersList);
      }
      currentParentNode=folderNode;
    }
 else {
      for (      Item curItem : (List<Item>)new ArrayList(((FolderItem)item).getChildren())) {
        addItemToRecycleBin(parentNode,curItem,foldersList);
      }
    }
  }
 else   if (item.getState() != null && item.getState().isDeleted()) {
    try {
      if (item.getProperty().getVersion().equals(ProxyRepositoryFactory.getInstance().getLastVersion(item.getProperty().getId()).getVersion())) {
        RepositoryNode repNode=new RepositoryNode(new RepositoryViewObject(item.getProperty()),currentParentNode,ENodeType.REPOSITORY_ELEMENT);
        repNode.setProperties(EProperties.CONTENT_TYPE,itemType);
        repNode.setProperties(EProperties.LABEL,item.getProperty().getLabel());
        currentParentNode.getChildren().add(repNode);
        repNode.setParent(currentParentNode);
      }
    }
 catch (    PersistenceException e) {
      ExceptionHandler.process(e);
    }
  }
 else {
    if (item instanceof ConnectionItem) {
      Connection connection=((ConnectionItem)item).getConnection();
      if (connection instanceof SAPConnection) {
        SAPConnection sapConnection=(SAPConnection)connection;
        EList<SAPFunctionUnit> funtions=sapConnection.getFuntions();
        if (funtions != null) {
          for (int i=0; i < funtions.size(); i++) {
            SAPFunctionUnit unit=funtions.get(i);
            if (SubItemHelper.isDeleted(unit)) {
              RepositoryNode tableNode=createSAPNode(new RepositoryViewObject(item.getProperty()),currentParentNode,unit);
              currentParentNode.getChildren().add(tableNode);
              tableNode.setParent(currentParentNode);
            }
 else {
              for (              MetadataTable table : ConnectionHelper.getTables(connection,unit)) {
                if (SubItemHelper.isDeleted(table)) {
                  RepositoryNode tableNode=createMetatableNode(currentParentNode,new RepositoryViewObject(item.getProperty()),table,ERepositoryObjectType.METADATA_CON_TABLE);
                  currentParentNode.getChildren().add(tableNode);
                  tableNode.setParent(currentParentNode);
                }
              }
            }
          }
        }
        EList<SAPIDocUnit> iDocs=sapConnection.getIDocs();
        if (iDocs != null) {
          for (int i=0; i < iDocs.size(); i++) {
            SAPIDocUnit unit=iDocs.get(i);
            if (SubItemHelper.isDeleted(unit)) {
              RepositoryNode tableNode=createSAPNode(new RepositoryViewObject(item.getProperty()),currentParentNode,unit);
              currentParentNode.getChildren().add(tableNode);
              tableNode.setParent(currentParentNode);
            }
          }
        }
        return;
      }
      for (      MetadataTable table : ConnectionHelper.getTables(connection)) {
        if (SubItemHelper.isDeleted(table)) {
          RepositoryNode tableNode=createMetatableNode(currentParentNode,new RepositoryViewObject(item.getProperty()),table,ERepositoryObjectType.METADATA_CON_TABLE);
          currentParentNode.getChildren().add(tableNode);
          tableNode.setParent(currentParentNode);
        }
      }
      if (connection != null) {
        QueriesConnection queriesConnection=connection.getQueries();
        if (queriesConnection != null) {
          for (          Query query : queriesConnection.getQuery()) {
            if (SubItemHelper.isDeleted(query)) {
              RepositoryNode queryNode=createQueryNode(currentParentNode,new RepositoryViewObject(item.getProperty()),query);
              currentParentNode.getChildren().add(queryNode);
              queryNode.setParent(currentParentNode);
            }
          }
        }
      }
    }
  }
}