Program: 50181
Project: 50181
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=LicaUtil.getDraftTreeLICA(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();
      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");
        ArrayList<Node> startNodeAncestors=treeTipRootPathMap.get(childTreeTipDescendants.get(0));
        Node startShallowestAncestor=null;
        if (startNodeAncestors.size() > 0) {
          startShallowestAncestor=startNodeAncestors.get(startNodeAncestors.size() - 1);
        }
        boolean isPolytomy=true;
        for (        JadeNode treeTip : childTreeTipDescendants) {
          ArrayList<Node> curAncestors=treeTipRootPathMap.get(treeTip);
          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){
  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();
      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");
        ArrayList<Node> startNodeAncestors=treeTipRootPathMap.get(childTreeTipDescendants.get(0));
        Node startShallowestAncestor=null;
        if (startNodeAncestors.size() > 0) {
          startShallowestAncestor=startNodeAncestors.get(startNodeAncestors.size() - 1);
        }
        boolean isPolytomy=true;
        for (        JadeNode treeTip : childTreeTipDescendants) {
          ArrayList<Node> curAncestors=treeTipRootPathMap.get(treeTip);
          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;
}