Program: 50155
Project: 50155
Buggy source:
/** 
 * A parallel method to find nestedChildOf rels across input trees, so that many can be processed concurrently. The idea here is that we just process each tree independently, comparing it to all other trees, looking for all nestedChildOf rels where this tree could be a parent. For this, we can use the structure of the trees to stop short of doing a complete allxall comparison of tree nodes, which saves some time. We then perform a (seemingly unavoidable) allxall comparison of each tree's nodes against all the summed biparts. We store the resulting parent/child information in the form of a map where they keys are the bipart ids of child biparts and the values are sets of bipart ids for their parents.
 * @param i
 * @param trees
 * @return
 */
private void processBipartsForTree(int i,List<Tree> trees){
  for (  TreeNode c : trees.get(i).internalNodes(NodeOrder.POSTORDER)) {
    if (c.isTheRoot()) {
      continue;
    }
    int cid=bipartId.get(bipartForTreeNode.get(c));
    for (TreeNode p=c.getParent(); !p.isTheRoot(); p=p.getParent()) {
      int pid=bipartId.get(bipartForTreeNode.get(p));
      nestedParents.get(cid).add(pid);
      nestedChildren.get(pid).add(cid);
    }
  }
  Tree P=trees.get(i);
  List<TreeNode> pRootChildren=P.getRoot().getChildren();
  pRootChildren.removeIf(isTip());
  for (int j=0; j < trees.size(); j++) {
    if (i == j) {
      continue;
    }
    List<TreeNode> qRootChildren=trees.get(j).getRoot().getChildren();
    qRootChildren.removeIf(isTip());
    boolean treesHaveIdenticalTaxa=bipartForTreeNode.get(pRootChildren.get(0)).hasIdenticalTaxonSetAs(bipartForTreeNode.get(qRootChildren.get(0)));
    LinkedList<TreeNode> pStack=new LinkedList<TreeNode>();
    for (pStack.addAll(pRootChildren); !pStack.isEmpty(); ) {
      TreeNode p=pStack.pop();
      if (p.isExternal()) {
        continue;
      }
      int pid=bipartId.get(bipartForTreeNode.get(p));
      TLongBipartition bp=bipart.get(pid);
      LinkedList<TreeNode> qStack=new LinkedList<TreeNode>();
      for (qStack.addAll(qRootChildren); !qStack.isEmpty(); ) {
        TreeNode q=qStack.pop();
        if (q.isExternal()) {
          continue;
        }
        int qid=bipartId.get(bipartForTreeNode.get(q));
        TLongBipartition bq=bipart.get(qid);
        if (bq.isNestedPartitionOf(bp)) {
          nestedParents.get(qid).add(pid);
          nestedChildren.get(pid).add(qid);
          if (!treesHaveIdenticalTaxa) {
            nestedAugmentingParents.get(qid).add(pid);
          }
        }
        if (bq.ingroup().containsAny(bp.ingroup())) {
          for (          TreeNode qc : q.getChildren()) {
            qStack.push(qc);
          }
        }
      }
      for (      TreeNode qn : qRootChildren) {
        boolean pOverlapsWithTreeQ=false;
        if (qn.isExternal()) {
          if (bp.ingroup().contains(this.nodeIdForLabel.get(qn.getLabel()))) {
            pOverlapsWithTreeQ=true;
          }
        }
 else         if (bp.ingroup().containsAny(bipartForTreeNode.get(qn).ingroup())) {
          pOverlapsWithTreeQ=true;
        }
        if (pOverlapsWithTreeQ) {
          for (          TreeNode pc : p.getChildren()) {
            pStack.push(pc);
          }
        }
      }
    }
  }
  for (  TreeNode node : P.internalNodes(NodeOrder.PREORDER)) {
    if (node.isTheRoot()) {
      continue;
    }
    int originalId=bipartId.get(bipartForTreeNode.get(node));
    TLongBipartition nodeBipart=bipart.get(originalId);
    for (    Integer sid : summedBipartIds) {
      TLongBipartition summedBipart=bipart.get(sid);
      boolean identicalTaxa=summedBipart.hasIdenticalTaxonSetAs(nodeBipart);
      if (summedBipart.isNestedPartitionOf(nodeBipart)) {
        nestedParents.get(originalId).add(sid);
        if (identicalTaxa) {
          nestedAugmentingParents.get(originalId).add(sid);
        }
      }
      if (nodeBipart.isNestedPartitionOf(summedBipart)) {
        nestedParents.get(sid).add(originalId);
        if (identicalTaxa) {
          nestedAugmentingParents.get(sid).add(originalId);
        }
      }
    }
  }
  System.out.println("String_Node_Str" + i);
}

Fixed version (ground truth):
/** 
 * A parallel method to find nestedChildOf rels across input trees, so that many can be processed concurrently. The idea here is that we just process each tree independently, comparing it to all other trees, looking for all nestedChildOf rels where this tree could be a parent. For this, we can use the structure of the trees to stop short of doing a complete allxall comparison of tree nodes, which saves some time. We then perform a (seemingly unavoidable) allxall comparison of each tree's nodes against all the summed biparts. We store the resulting parent/child information in the form of a map where they keys are the bipart ids of child biparts and the values are sets of bipart ids for their parents.
 * @param i
 * @param trees
 * @return
 */
private void processBipartsForTree(int i,List<Tree> trees){
  for (  TreeNode c : trees.get(i).internalNodes(NodeOrder.POSTORDER)) {
    if (c.isTheRoot()) {
      continue;
    }
    int cid=bipartId.get(bipartForTreeNode.get(c));
    for (TreeNode p=c.getParent(); !p.isTheRoot(); p=p.getParent()) {
      int pid=bipartId.get(bipartForTreeNode.get(p));
      nestedParents.get(cid).add(pid);
      nestedChildren.get(pid).add(cid);
    }
  }
  Tree P=trees.get(i);
  List<TreeNode> pRootChildren=P.getRoot().getChildren();
  pRootChildren.removeIf(isTip());
  for (int j=0; j < trees.size(); j++) {
    if (i == j) {
      continue;
    }
    List<TreeNode> qRootChildren=trees.get(j).getRoot().getChildren();
    qRootChildren.removeIf(isTip());
    boolean treesHaveIdenticalTaxa=bipartForTreeNode.get(pRootChildren.get(0)).hasIdenticalTaxonSetAs(bipartForTreeNode.get(qRootChildren.get(0)));
    LinkedList<TreeNode> pStack=new LinkedList<TreeNode>();
    HashSet<TreeNode> pvisited=new HashSet<TreeNode>();
    for (pStack.addAll(pRootChildren); !pStack.isEmpty(); ) {
      TreeNode p=pStack.pop();
      if (p.isExternal()) {
        continue;
      }
      if (pvisited.contains(p)) {
        continue;
      }
 else {
        pvisited.add(p);
      }
      int pid=bipartId.get(bipartForTreeNode.get(p));
      TLongBipartition bp=bipart.get(pid);
      LinkedList<TreeNode> qStack=new LinkedList<TreeNode>();
      HashSet<TreeNode> qvisited=new HashSet<TreeNode>();
      for (qStack.addAll(qRootChildren); !qStack.isEmpty(); ) {
        TreeNode q=qStack.pop();
        if (q.isExternal()) {
          continue;
        }
        if (qvisited.contains(q)) {
          continue;
        }
 else {
          qvisited.add(q);
        }
        int qid=bipartId.get(bipartForTreeNode.get(q));
        TLongBipartition bq=bipart.get(qid);
        if (bq.isNestedPartitionOf(bp)) {
          nestedParents.get(qid).add(pid);
          nestedChildren.get(pid).add(qid);
          if (!treesHaveIdenticalTaxa) {
            nestedAugmentingParents.get(qid).add(pid);
          }
        }
        if (bq.ingroup().containsAny(bp.ingroup())) {
          for (          TreeNode qc : q.getChildren()) {
            qStack.push(qc);
          }
        }
      }
      for (      TreeNode qn : qRootChildren) {
        boolean pOverlapsWithTreeQ=false;
        if (qn.isExternal()) {
          if (bp.ingroup().contains(this.nodeIdForLabel.get(qn.getLabel()))) {
            pOverlapsWithTreeQ=true;
          }
        }
 else         if (bp.ingroup().containsAny(bipartForTreeNode.get(qn).ingroup())) {
          pOverlapsWithTreeQ=true;
        }
        if (pOverlapsWithTreeQ) {
          for (          TreeNode pc : p.getChildren()) {
            pStack.push(pc);
          }
        }
      }
    }
  }
  for (  TreeNode node : P.internalNodes(NodeOrder.PREORDER)) {
    if (node.isTheRoot()) {
      continue;
    }
    int originalId=bipartId.get(bipartForTreeNode.get(node));
    TLongBipartition nodeBipart=bipart.get(originalId);
    for (    Integer sid : summedBipartIds) {
      TLongBipartition summedBipart=bipart.get(sid);
      boolean identicalTaxa=summedBipart.hasIdenticalTaxonSetAs(nodeBipart);
      if (summedBipart.isNestedPartitionOf(nodeBipart)) {
        nestedParents.get(originalId).add(sid);
        if (identicalTaxa) {
          nestedAugmentingParents.get(originalId).add(sid);
        }
      }
      if (nodeBipart.isNestedPartitionOf(summedBipart)) {
        nestedParents.get(sid).add(originalId);
        if (identicalTaxa) {
          nestedAugmentingParents.get(sid).add(originalId);
        }
      }
    }
  }
  System.out.println("String_Node_Str" + i);
}