Program: 50179
Project: 50179
Buggy source:
/** 
 * Get a subtree out of the draft tree topology for the indicated tips.
 * @param tips
 * @return draftSubtree
 */
public JadeNode extractDraftSubtreeForTipNodes(Iterable<Node> tips){
  Map<Node,ArrayList<Node>> treeTipRootPathMap=getTreeTipRootPathMap(tips);
  HashMap<Node,JadeNode> graphNodeTreeNodeMap=new HashMap<Node,JadeNode>();
  HashMap<JadeNode,Node> treeNodeGraphNodeMap=new HashMap<JadeNode,Node>();
  HashMap<JadeNode,LinkedList<Node>> treeTipGraphMRCADescendantsMap=new HashMap<JadeNode,LinkedList<Node>>();
  for (  Node tipNode : treeTipRootPathMap.keySet()) {
    JadeNode treeTip=new JadeNode();
    treeTip.assocObject("String_Node_Str",tipNode);
    treeTip.setName((String)tipNode.getProperty("String_Node_Str"));
    graphNodeTreeNodeMap.put(tipNode,treeTip);
    treeNodeGraphNodeMap.put(treeTip,tipNode);
    LinkedList<Node> tipDescendants=new LinkedList<Node>();
    for (    long nid : (long[])tipNode.getProperty("String_Node_Str")) {
      tipDescendants.add(graphDb.getNodeById(nid));
    }
    treeTipGraphMRCADescendantsMap.put(treeTip,tipDescendants);
  }
  HashMap<JadeNode,LinkedList<JadeNode>> treeNodeTreeTipDescendantsMap=new HashMap<JadeNode,LinkedList<JadeNode>>();
  LinkedList<JadeNode> stack=new LinkedList<JadeNode>();
  JadeNode root=new JadeNode();
  stack.add(root);
  treeNodeTreeTipDescendantsMap.put(root,new LinkedList<JadeNode>(graphNodeTreeNodeMap.values()));
  while (stack.size() > 0) {
    System.out.println(stack.size() + "String_Node_Str");
    JadeNode treeNode=stack.remove(0);
    LinkedList<Node> allDescendantGraphTips=new LinkedList<Node>();
    for (    JadeNode treeTip : treeNodeTreeTipDescendantsMap.get(treeNode)) {
      System.out.println(treeTip.getName());
      allDescendantGraphTips.addAll(treeTipGraphMRCADescendantsMap.get(treeTip));
    }
    Node graphNode=getDraftTreeMRCAForNodes(allDescendantGraphTips);
    treeNode.assocObject("String_Node_Str",graphNode);
    if (graphNode.hasProperty("String_Node_Str")) {
      treeNode.setName((String)graphNode.getProperty("String_Node_Str"));
    }
    System.out.println("String_Node_Str" + treeNode.getName());
    HashMap<Node,LinkedList<JadeNode>> childNodeTreeTipDescendantsMap=new HashMap<Node,LinkedList<JadeNode>>();
    for (    JadeNode curDescendantTreeNode : treeNodeTreeTipDescendantsMap.get(treeNode)) {
      System.out.println("String_Node_Str" + curDescendantTreeNode.getName());
      Node curDescendantGraphNode=treeNodeGraphNodeMap.get(curDescendantTreeNode);
      Node curDeepestAncestor=null;
      if (treeTipRootPathMap.get(curDescendantGraphNode).size() > 0) {
        curDeepestAncestor=treeTipRootPathMap.get(curDescendantGraphNode).remove(0);
      }
 else {
        curDeepestAncestor=(Node)treeNode.getObject("String_Node_Str");
      }
      if (curDeepestAncestor.hasProperty("String_Node_Str")) {
        System.out.println("String_Node_Str" + curDeepestAncestor.getProperty("String_Node_Str"));
      }
      if (!childNodeTreeTipDescendantsMap.containsKey(curDeepestAncestor)) {
        childNodeTreeTipDescendantsMap.put(curDeepestAncestor,new LinkedList<JadeNode>());
      }
      childNodeTreeTipDescendantsMap.get(curDeepestAncestor).add(curDescendantTreeNode);
    }
    for (    Entry<Node,LinkedList<JadeNode>> childToAdd : childNodeTreeTipDescendantsMap.entrySet()) {
      LinkedList<JadeNode> childTreeTipDescendants=childToAdd.getValue();
      System.out.println("String_Node_Str");
      System.out.println(Arrays.toString(childTreeTipDescendants.toArray()));
      if (childTreeTipDescendants.size() == 1) {
        treeNode.addChild(childTreeTipDescendants.get(0));
        continue;
      }
      Node childGraphNode=childToAdd.getKey();
      JadeNode childTreeNode=new JadeNode();
      childTreeNode.assocObject("String_Node_Str",childGraphNode);
      if (childGraphNode.hasProperty("String_Node_Str")) {
        childTreeNode.setName((String)childGraphNode.getProperty("String_Node_Str"));
      }
      if (childTreeTipDescendants.size() == 2) {
        for (        JadeNode treeTip : childTreeTipDescendants) {
          childTreeNode.addChild(treeTip);
        }
      }
 else {
        System.out.println(treeNode.getName() + "String_Node_Str");
        System.out.println("String_Node_Str");
        Node graphNodeForTip=treeNodeGraphNodeMap.get(childTreeTipDescendants.get(0));
        ArrayList<Node> startNodeAncestors=treeTipRootPathMap.get(graphNodeForTip);
        Node startShallowestAncestor=null;
        System.out.println("String_Node_Str");
        System.out.println(Arrays.toString(startNodeAncestors.toArray()));
        if (startNodeAncestors.size() > 0) {
          startShallowestAncestor=startNodeAncestors.get(startNodeAncestors.size() - 1);
        }
        boolean isPolytomy=true;
        for (        JadeNode treeTip : childTreeTipDescendants) {
          Node graphTip=treeNodeGraphNodeMap.get(treeTip);
          ArrayList<Node> curAncestors=treeTipRootPathMap.get(graphTip);
          Node curShallowestAncestor=curAncestors.get(curAncestors.size() - 1);
          if (!startShallowestAncestor.equals(curShallowestAncestor)) {
            stack.add(0,childTreeNode);
            treeNodeTreeTipDescendantsMap.put(childTreeNode,childTreeTipDescendants);
            isPolytomy=false;
            break;
          }
        }
        if (isPolytomy) {
          for (          JadeNode treeTip : childTreeTipDescendants) {
            childTreeNode.addChild(treeTip);
          }
        }
      }
      treeNode.addChild(childTreeNode);
    }
  }
  return root;
}

Fixed version (ground truth):
/** 
 * Get a subtree out of the draft tree topology for the indicated tips.
 * @param tips
 * @return draftSubtree
 */
public JadeNode extractDraftSubtreeForTipNodes(Iterable<Node> tips){
  Node mrca=getDraftTreeMRCAForNodes(tips);
  System.out.println("String_Node_Str" + mrca);
  Map<Node,ArrayList<Node>> treeTipToMRCAPathMap=getTreeTipRootPathMap(tips,mrca);
  HashMap<Node,JadeNode> graphNodeTreeNodeMap=new HashMap<Node,JadeNode>();
  HashMap<JadeNode,Node> treeNodeGraphNodeMap=new HashMap<JadeNode,Node>();
  HashMap<JadeNode,LinkedList<Node>> treeTipGraphMRCADescendantsMap=new HashMap<JadeNode,LinkedList<Node>>();
  for (  Node tipNode : treeTipToMRCAPathMap.keySet()) {
    JadeNode treeTip=new JadeNode();
    treeTip.assocObject("String_Node_Str",tipNode);
    treeTip.setName((String)tipNode.getProperty("String_Node_Str"));
    graphNodeTreeNodeMap.put(tipNode,treeTip);
    treeNodeGraphNodeMap.put(treeTip,tipNode);
    LinkedList<Node> tipDescendants=new LinkedList<Node>();
    for (    long nid : (long[])tipNode.getProperty("String_Node_Str")) {
      tipDescendants.add(graphDb.getNodeById(nid));
    }
    treeTipGraphMRCADescendantsMap.put(treeTip,tipDescendants);
  }
  HashMap<JadeNode,LinkedList<JadeNode>> treeNodeTreeTipDescendantsMap=new HashMap<JadeNode,LinkedList<JadeNode>>();
  LinkedList<JadeNode> stack=new LinkedList<JadeNode>();
  JadeNode root=new JadeNode();
  stack.add(root);
  treeNodeTreeTipDescendantsMap.put(root,new LinkedList<JadeNode>(graphNodeTreeNodeMap.values()));
  while (stack.size() > 0) {
    System.out.println(stack.size() + "String_Node_Str");
    JadeNode treeNode=stack.remove(0);
    LinkedList<Node> allDescendantGraphTips=new LinkedList<Node>();
    for (    JadeNode treeTip : treeNodeTreeTipDescendantsMap.get(treeNode)) {
      System.out.println(treeTip.getName());
      allDescendantGraphTips.addAll(treeTipGraphMRCADescendantsMap.get(treeTip));
    }
    Node graphNode=getDraftTreeMRCAForNodes(allDescendantGraphTips);
    treeNode.assocObject("String_Node_Str",graphNode);
    if (graphNode.hasProperty("String_Node_Str")) {
      treeNode.setName((String)graphNode.getProperty("String_Node_Str"));
    }
    System.out.println("String_Node_Str" + treeNode.getName());
    HashMap<Node,LinkedList<JadeNode>> childNodeTreeTipDescendantsMap=new HashMap<Node,LinkedList<JadeNode>>();
    for (    JadeNode curDescendantTreeNode : treeNodeTreeTipDescendantsMap.get(treeNode)) {
      System.out.println("String_Node_Str" + curDescendantTreeNode.getName());
      Node curDescendantGraphNode=treeNodeGraphNodeMap.get(curDescendantTreeNode);
      Node curDeepestAncestor=null;
      if (treeTipToMRCAPathMap.get(curDescendantGraphNode).size() > 0) {
        curDeepestAncestor=treeTipToMRCAPathMap.get(curDescendantGraphNode).remove(0);
      }
 else {
        curDeepestAncestor=(Node)treeNode.getObject("String_Node_Str");
      }
      if (curDeepestAncestor.hasProperty("String_Node_Str")) {
        System.out.println("String_Node_Str" + curDeepestAncestor.getProperty("String_Node_Str"));
      }
      if (!childNodeTreeTipDescendantsMap.containsKey(curDeepestAncestor)) {
        childNodeTreeTipDescendantsMap.put(curDeepestAncestor,new LinkedList<JadeNode>());
      }
      childNodeTreeTipDescendantsMap.get(curDeepestAncestor).add(curDescendantTreeNode);
    }
    for (    Entry<Node,LinkedList<JadeNode>> childToAdd : childNodeTreeTipDescendantsMap.entrySet()) {
      LinkedList<JadeNode> childTreeTipDescendants=childToAdd.getValue();
      System.out.println("String_Node_Str");
      System.out.println(Arrays.toString(childTreeTipDescendants.toArray()));
      if (childTreeTipDescendants.size() == 1) {
        treeNode.addChild(childTreeTipDescendants.get(0));
        continue;
      }
      Node childGraphNode=childToAdd.getKey();
      JadeNode childTreeNode=new JadeNode();
      childTreeNode.assocObject("String_Node_Str",childGraphNode);
      if (childGraphNode.hasProperty("String_Node_Str")) {
        childTreeNode.setName((String)childGraphNode.getProperty("String_Node_Str"));
      }
      if (childTreeTipDescendants.size() == 2) {
        for (        JadeNode treeTip : childTreeTipDescendants) {
          childTreeNode.addChild(treeTip);
        }
      }
 else {
        System.out.println(treeNode.getName() + "String_Node_Str");
        System.out.println("String_Node_Str");
        Node graphNodeForTip=treeNodeGraphNodeMap.get(childTreeTipDescendants.get(0));
        ArrayList<Node> startNodeAncestors=treeTipToMRCAPathMap.get(graphNodeForTip);
        Node startShallowestAncestor=null;
        System.out.println("String_Node_Str");
        System.out.println(Arrays.toString(startNodeAncestors.toArray()));
        if (startNodeAncestors.size() > 0) {
          startShallowestAncestor=startNodeAncestors.get(startNodeAncestors.size() - 1);
        }
        boolean isPolytomy=true;
        for (        JadeNode treeTip : childTreeTipDescendants) {
          Node graphTip=treeNodeGraphNodeMap.get(treeTip);
          ArrayList<Node> curAncestors=treeTipToMRCAPathMap.get(graphTip);
          Node curShallowestAncestor=curAncestors.get(curAncestors.size() - 1);
          if (!startShallowestAncestor.equals(curShallowestAncestor)) {
            stack.add(0,childTreeNode);
            treeNodeTreeTipDescendantsMap.put(childTreeNode,childTreeTipDescendants);
            isPolytomy=false;
            break;
          }
        }
        if (isPolytomy) {
          for (          JadeNode treeTip : childTreeTipDescendants) {
            childTreeNode.addChild(treeTip);
          }
        }
      }
      treeNode.addChild(childTreeNode);
    }
  }
  return root;
}