Program: 170789
Project: 170789
Buggy source:
public static Map<String,Long> calculateToolbarStates(ISelectedContent[] currentContent,String viewID_unused){
  Map<String,Long> mapNewToolbarStates=new HashMap<>();
  String[] itemsNeedingSelection={};
  String[] itemsNeedingRealDMSelection={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
  String[] itemsRequiring1DMwithHash={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
  String[] itemsRequiring1DMSelection={};
  int numSelection=currentContent.length;
  boolean hasSelection=numSelection > 0;
  boolean has1Selection=numSelection == 1;
  for (int i=0; i < itemsNeedingSelection.length; i++) {
    String itemID=itemsNeedingSelection[i];
    mapNewToolbarStates.put(itemID,hasSelection ? UIToolBarItem.STATE_ENABLED : 0);
  }
  TableView tv=SelectedContentManager.getCurrentlySelectedTableView();
  boolean hasRealDM=tv != null;
  if (!hasRealDM && numSelection > 0) {
    hasRealDM=true;
    for (int i=0; i < currentContent.length; i++) {
      ISelectedContent content=currentContent[i];
      DownloadManager dm=content.getDownloadManager();
      if (dm == null) {
        hasRealDM=false;
        break;
      }
    }
  }
  if (!hasRealDM) {
    MultipleDocumentInterfaceSWT mdi=UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
    if (mdi != null) {
      MdiEntrySWT entry=mdi.getCurrentEntrySWT();
      if (entry != null) {
        if (entry.getDatasource() instanceof DownloadManager) {
          hasRealDM=true;
        }
 else         if ((entry instanceof UIPluginView) && (((UIPluginView)entry).getDataSource() instanceof DownloadManager)) {
          hasRealDM=true;
        }
      }
    }
  }
  boolean canStart=false;
  boolean canStop=false;
  boolean canRemoveFileInfo=false;
  boolean canRunFileInfo=false;
  boolean hasDM=false;
  if (currentContent.length > 0 && hasRealDM) {
    boolean canMoveUp=false;
    boolean canMoveDown=false;
    boolean canDownload=false;
    GlobalManager gm=null;
    for (int i=0; i < currentContent.length; i++) {
      ISelectedContent content=currentContent[i];
      DownloadManager dm=content.getDownloadManager();
      if (dm == null) {
        if (!canDownload && content.getDownloadInfo() != null) {
          canDownload=true;
        }
        continue;
      }
      if (gm == null) {
        gm=dm.getGlobalManager();
      }
      int fileIndex=content.getFileIndex();
      if (fileIndex == -1) {
        if (!canMoveUp && gm.isMoveableUp(dm)) {
          canMoveUp=true;
        }
        if (!canMoveDown && gm.isMoveableDown(dm)) {
          canMoveDown=true;
        }
        hasDM=true;
        if (!canStart && ManagerUtils.isStartable(dm)) {
          canStart=true;
        }
        if (!canStop && ManagerUtils.isStopable(dm)) {
          canStop=true;
        }
      }
 else {
        DiskManagerFileInfoSet fileInfos=dm.getDiskManagerFileInfoSet();
        if (fileIndex < fileInfos.nbFiles()) {
          DiskManagerFileInfo fileInfo=fileInfos.getFiles()[fileIndex];
          if (!canStart && (fileInfo.isSkipped())) {
            canStart=true;
          }
          if (!canStop && !fileInfo.isSkipped()) {
            canStop=true;
          }
          if (!canRemoveFileInfo && !fileInfo.isSkipped()) {
            int storageType=fileInfo.getStorageType();
            if (storageType == DiskManagerFileInfo.ST_LINEAR || storageType == DiskManagerFileInfo.ST_COMPACT) {
              canRemoveFileInfo=true;
            }
          }
          if (!canRunFileInfo && fileInfo.getAccessMode() == DiskManagerFileInfo.READ && fileInfo.getDownloaded() == fileInfo.getLength() && fileInfo.getFile(true).exists()) {
            canRunFileInfo=true;
          }
        }
      }
    }
    boolean canRemove=hasDM || canRemoveFileInfo;
    mapNewToolbarStates.put("String_Node_Str",canRemove ? UIToolBarItem.STATE_ENABLED : 0);
    mapNewToolbarStates.put("String_Node_Str",canDownload ? UIToolBarItem.STATE_ENABLED : 0);
    if (currentContent.length == 1) {
      mapNewToolbarStates.put("String_Node_Str",canMoveUp ? UIToolBarItem.STATE_ENABLED : 0);
      mapNewToolbarStates.put("String_Node_Str",canMoveDown ? UIToolBarItem.STATE_ENABLED : 0);
    }
  }
  boolean canRun=has1Selection && ((hasDM && !canRunFileInfo) || (!hasDM && canRunFileInfo));
  if (canRun) {
    ISelectedContent content=currentContent[0];
    DownloadManager dm=content.getDownloadManager();
    if (dm == null) {
      canRun=false;
    }
 else {
      TOTorrent torrent=dm.getTorrent();
      if (torrent == null) {
        canRun=false;
      }
 else       if (!dm.getAssumedComplete() && torrent.isSimpleTorrent()) {
        canRun=false;
      }
    }
  }
  mapNewToolbarStates.put("String_Node_Str",canRun ? UIToolBarItem.STATE_ENABLED : 0);
  mapNewToolbarStates.put("String_Node_Str",canStart ? UIToolBarItem.STATE_ENABLED : 0);
  mapNewToolbarStates.put("String_Node_Str",canStop ? UIToolBarItem.STATE_ENABLED : 0);
  mapNewToolbarStates.put("String_Node_Str",canStart || canStop ? UIToolBarItem.STATE_ENABLED : 0);
  for (int i=0; i < itemsNeedingRealDMSelection.length; i++) {
    String itemID=itemsNeedingRealDMSelection[i];
    if (!mapNewToolbarStates.containsKey(itemID)) {
      mapNewToolbarStates.put(itemID,hasSelection && hasDM && hasRealDM ? UIToolBarItem.STATE_ENABLED : 0);
    }
  }
  for (int i=0; i < itemsRequiring1DMSelection.length; i++) {
    String itemID=itemsRequiring1DMSelection[i];
    if (!mapNewToolbarStates.containsKey(itemID)) {
      mapNewToolbarStates.put(itemID,has1Selection && hasDM ? UIToolBarItem.STATE_ENABLED : 0);
    }
  }
  for (int i=0; i < itemsRequiring1DMwithHash.length; i++) {
    String itemID=itemsRequiring1DMwithHash[i];
    if (!mapNewToolbarStates.containsKey(itemID)) {
      mapNewToolbarStates.put(itemID,hasDM ? UIToolBarItem.STATE_ENABLED : 0);
    }
  }
  mapNewToolbarStates.put("String_Node_Str",has1Selection && (!(currentContent[0] instanceof ISelectedVuzeFileContent)) && currentContent[0].getDownloadManager() == null && (currentContent[0].getHash() != null || currentContent[0].getDownloadInfo() != null) ? UIToolBarItem.STATE_ENABLED : 0);
  if (tv != null) {
    TableColumn tc=tv.getTableColumn(RankItem.COLUMN_ID);
    if (tc != null && !tc.isVisible()) {
      mapNewToolbarStates.put("String_Node_Str",0L);
      mapNewToolbarStates.put("String_Node_Str",0L);
    }
  }
  return mapNewToolbarStates;
}

Fixed version (ground truth):
public static Map<String,Long> calculateToolbarStates(ISelectedContent[] currentContent,String viewID_unused){
  Map<String,Long> mapNewToolbarStates=new HashMap<>();
  String[] itemsNeedingSelection={};
  String[] itemsNeedingRealDMSelection={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
  String[] itemsRequiring1DMwithHash={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
  String[] itemsRequiring1DMSelection={};
  int numSelection=currentContent.length;
  boolean hasSelection=numSelection > 0;
  boolean has1Selection=numSelection == 1;
  for (int i=0; i < itemsNeedingSelection.length; i++) {
    String itemID=itemsNeedingSelection[i];
    mapNewToolbarStates.put(itemID,hasSelection ? UIToolBarItem.STATE_ENABLED : 0);
  }
  TableView tv=SelectedContentManager.getCurrentlySelectedTableView();
  boolean hasRealDM=tv != null;
  if (!hasRealDM && numSelection > 0) {
    hasRealDM=true;
    for (int i=0; i < currentContent.length; i++) {
      ISelectedContent content=currentContent[i];
      DownloadManager dm=content.getDownloadManager();
      if (dm == null) {
        hasRealDM=false;
        break;
      }
    }
  }
  if (!hasRealDM) {
    MultipleDocumentInterfaceSWT mdi=UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
    if (mdi != null) {
      MdiEntrySWT entry=mdi.getCurrentEntrySWT();
      if (entry != null) {
        if (entry.getDatasource() instanceof DownloadManager) {
          hasRealDM=true;
        }
 else         if ((entry instanceof UIPluginView) && (((UIPluginView)entry).getDataSource() instanceof DownloadManager)) {
          hasRealDM=true;
        }
      }
    }
  }
  boolean canStart=false;
  boolean canStop=false;
  boolean canRemoveFileInfo=false;
  boolean canRunFileInfo=false;
  boolean hasDM=false;
  boolean canRecheck=false;
  if (currentContent.length > 0 && hasRealDM) {
    boolean canMoveUp=false;
    boolean canMoveDown=false;
    boolean canDownload=false;
    GlobalManager gm=null;
    for (int i=0; i < currentContent.length; i++) {
      ISelectedContent content=currentContent[i];
      DownloadManager dm=content.getDownloadManager();
      if (dm == null) {
        if (!canDownload && content.getDownloadInfo() != null) {
          canDownload=true;
        }
        continue;
      }
      if (gm == null) {
        gm=dm.getGlobalManager();
      }
      int fileIndex=content.getFileIndex();
      if (fileIndex == -1) {
        if (!canMoveUp && gm.isMoveableUp(dm)) {
          canMoveUp=true;
        }
        if (!canMoveDown && gm.isMoveableDown(dm)) {
          canMoveDown=true;
        }
        hasDM=true;
        if (!canStart && ManagerUtils.isStartable(dm)) {
          canStart=true;
        }
        if (!canStop && ManagerUtils.isStopable(dm)) {
          canStop=true;
        }
      }
 else {
        DiskManagerFileInfoSet fileInfos=dm.getDiskManagerFileInfoSet();
        if (fileIndex < fileInfos.nbFiles()) {
          DiskManagerFileInfo fileInfo=fileInfos.getFiles()[fileIndex];
          if (!canStart && (fileInfo.isSkipped())) {
            canStart=true;
          }
          if (!canStop && !fileInfo.isSkipped()) {
            canStop=true;
          }
          if (!canRemoveFileInfo && !fileInfo.isSkipped()) {
            int storageType=fileInfo.getStorageType();
            if (storageType == DiskManagerFileInfo.ST_LINEAR || storageType == DiskManagerFileInfo.ST_COMPACT) {
              canRemoveFileInfo=true;
            }
          }
          if (!canRunFileInfo && fileInfo.getAccessMode() == DiskManagerFileInfo.READ && fileInfo.getDownloaded() == fileInfo.getLength() && fileInfo.getFile(true).exists()) {
            canRunFileInfo=true;
          }
        }
      }
      canRecheck=canRecheck || dm.canForceRecheck();
    }
    boolean canRemove=hasDM || canRemoveFileInfo;
    mapNewToolbarStates.put("String_Node_Str",canRemove ? UIToolBarItem.STATE_ENABLED : 0);
    mapNewToolbarStates.put("String_Node_Str",canDownload ? UIToolBarItem.STATE_ENABLED : 0);
    if (currentContent.length == 1) {
      mapNewToolbarStates.put("String_Node_Str",canMoveUp ? UIToolBarItem.STATE_ENABLED : 0);
      mapNewToolbarStates.put("String_Node_Str",canMoveDown ? UIToolBarItem.STATE_ENABLED : 0);
    }
  }
  boolean canRun=has1Selection && ((hasDM && !canRunFileInfo) || (!hasDM && canRunFileInfo));
  if (canRun) {
    ISelectedContent content=currentContent[0];
    DownloadManager dm=content.getDownloadManager();
    if (dm == null) {
      canRun=false;
    }
 else {
      TOTorrent torrent=dm.getTorrent();
      if (torrent == null) {
        canRun=false;
      }
 else       if (!dm.getAssumedComplete() && torrent.isSimpleTorrent()) {
        canRun=false;
      }
    }
  }
  mapNewToolbarStates.put("String_Node_Str",canRun ? UIToolBarItem.STATE_ENABLED : 0);
  mapNewToolbarStates.put("String_Node_Str",canStart ? UIToolBarItem.STATE_ENABLED : 0);
  mapNewToolbarStates.put("String_Node_Str",canStop ? UIToolBarItem.STATE_ENABLED : 0);
  mapNewToolbarStates.put("String_Node_Str",canStart || canStop ? UIToolBarItem.STATE_ENABLED : 0);
  for (int i=0; i < itemsNeedingRealDMSelection.length; i++) {
    String itemID=itemsNeedingRealDMSelection[i];
    if (!mapNewToolbarStates.containsKey(itemID)) {
      mapNewToolbarStates.put(itemID,hasSelection && hasDM && hasRealDM ? UIToolBarItem.STATE_ENABLED : 0);
    }
  }
  for (int i=0; i < itemsRequiring1DMSelection.length; i++) {
    String itemID=itemsRequiring1DMSelection[i];
    if (!mapNewToolbarStates.containsKey(itemID)) {
      mapNewToolbarStates.put(itemID,has1Selection && hasDM ? UIToolBarItem.STATE_ENABLED : 0);
    }
  }
  for (int i=0; i < itemsRequiring1DMwithHash.length; i++) {
    String itemID=itemsRequiring1DMwithHash[i];
    if (!mapNewToolbarStates.containsKey(itemID)) {
      mapNewToolbarStates.put(itemID,hasDM ? UIToolBarItem.STATE_ENABLED : 0);
    }
  }
  mapNewToolbarStates.put("String_Node_Str",has1Selection && (!(currentContent[0] instanceof ISelectedVuzeFileContent)) && currentContent[0].getDownloadManager() == null && (currentContent[0].getHash() != null || currentContent[0].getDownloadInfo() != null) ? UIToolBarItem.STATE_ENABLED : 0);
  if (tv != null) {
    TableColumn tc=tv.getTableColumn(RankItem.COLUMN_ID);
    if (tc != null && !tc.isVisible()) {
      mapNewToolbarStates.put("String_Node_Str",0L);
      mapNewToolbarStates.put("String_Node_Str",0L);
    }
  }
  mapNewToolbarStates.put(TU_ITEM_RECHECK,canRecheck ? UIToolBarItem.STATE_ENABLED : 0);
  return mapNewToolbarStates;
}