Program: 123817
Project: 123817
Buggy source:
private void prepareModelFromOutput(List<FOXTreeNode> foxTreeNodes,TreeNode parent){
  TreeNode realParent=XmlMapUtil.getRealParentNode(parent);
  for (  FOXTreeNode foxNode : foxTreeNodes) {
    TreeNode createTreeNode=createModel();
    String label=foxNode.getLabel();
    createTreeNode.setName(label);
    if (foxNode instanceof Element) {
      createTreeNode.setNodeType(NodeType.ELEMENT);
      if (foxNode.isChoice()) {
        createTreeNode.setChoice(foxNode.isChoice());
      }
 else       if (foxNode.isSubstitution()) {
        createTreeNode.setSubstitution(foxNode.isSubstitution());
      }
    }
 else     if (foxNode instanceof Attribute) {
      createTreeNode.setNodeType(NodeType.ATTRIBUT);
    }
 else     if (foxNode instanceof NameSpaceNode) {
      createTreeNode.setNodeType(NodeType.NAME_SPACE);
      createTreeNode.setDefaultValue(foxNode.getDefaultValue());
      if (createTreeNode.getName() == null || createTreeNode.getName().equals("String_Node_Str")) {
        createTreeNode.setName(XmlMapUtil.DEFAULT_NAME_SPACE_PREFIX);
      }
    }
    if (foxNode.getDataType() != null && "String_Node_Str".equals(foxNode.getDataType())) {
      createTreeNode.setType(foxNode.getDataType());
    }
 else {
      createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
    }
    String xPath=XmlMapUtil.getXPath(realParent.getXpath(),label,createTreeNode.getNodeType());
    createTreeNode.setXpath(xPath);
    if (createTreeNode.isSubstitution() || createTreeNode.isChoice()) {
      if (isMappedChoiceSubsOutput(foxNode,realParent.getXpath())) {
        parent.getChildren().add(createTreeNode);
      }
    }
 else {
      String subXpath=xPath.substring(schemaNode.getXpath().length() + 1,xPath.length());
      XMLFileNode found=findXmlFileNode(subXpath,root);
      if (found == null) {
        found=findXmlFileNode(subXpath,group);
        if (found != null) {
          groupElements.add(createTreeNode);
        }
      }
      if (found == null) {
        found=findXmlFileNode(subXpath,loop);
        if (found != null) {
          if (outputLoop == null) {
            outputLoop=createTreeNode;
            outputLoop.setLoop(true);
            outputLoop.setOptional(foxNode.isOptional());
          }
        }
      }
      if (found == null) {
        continue;
      }
 else {
        xpathAndOrder.put(createTreeNode.getXpath(),found.getOrder());
        Integer index=null;
        List<TreeNode> children=parent.getChildren();
        for (int i=0; i < children.size(); i++) {
          Integer order=xpathAndOrder.get(children.get(i).getXpath());
          if (found.getOrder() < order) {
            index=i;
          }
        }
        if (index == null) {
          parent.getChildren().add(createTreeNode);
        }
 else {
          parent.getChildren().add(index,createTreeNode);
        }
      }
    }
    prepareModelFromOutput(foxNode.getChildren(),createTreeNode);
  }
}

Fixed version (ground truth):
private void prepareModelFromOutput(List<FOXTreeNode> foxTreeNodes,TreeNode parent){
  TreeNode realParent=XmlMapUtil.getRealParentNode(parent);
  for (  FOXTreeNode foxNode : foxTreeNodes) {
    TreeNode createTreeNode=createModel();
    String label=foxNode.getLabel();
    createTreeNode.setName(label);
    if (foxNode instanceof Element) {
      createTreeNode.setNodeType(NodeType.ELEMENT);
      if (foxNode.isChoice()) {
        createTreeNode.setChoice(foxNode.isChoice());
      }
 else       if (foxNode.isSubstitution()) {
        createTreeNode.setSubstitution(foxNode.isSubstitution());
      }
    }
 else     if (foxNode instanceof Attribute) {
      createTreeNode.setNodeType(NodeType.ATTRIBUT);
    }
 else     if (foxNode instanceof NameSpaceNode) {
      createTreeNode.setNodeType(NodeType.NAME_SPACE);
      createTreeNode.setDefaultValue(foxNode.getDefaultValue());
      if (createTreeNode.getName() == null || createTreeNode.getName().equals("String_Node_Str")) {
        createTreeNode.setName(XmlMapUtil.DEFAULT_NAME_SPACE_PREFIX);
      }
    }
    if (foxNode.getDataType() != null && "String_Node_Str".equals(foxNode.getDataType())) {
      createTreeNode.setType(foxNode.getDataType());
    }
 else {
      createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
    }
    String xPath=XmlMapUtil.getXPath(realParent.getXpath(),label,createTreeNode.getNodeType());
    createTreeNode.setXpath(xPath);
    if (createTreeNode.isSubstitution() || createTreeNode.isChoice()) {
      if (isMappedChoiceSubsOutput(foxNode,realParent.getXpath())) {
        parent.getChildren().add(createTreeNode);
      }
    }
 else {
      String subXpath=xPath.substring(schemaNode.getXpath().length() + 1,xPath.length());
      XMLFileNode found=findXmlFileNode(subXpath,root);
      if (found == null) {
        found=findXmlFileNode(subXpath,group);
        if (found != null) {
          groupElements.add(createTreeNode);
        }
      }
      if (found == null) {
        found=findXmlFileNode(subXpath,loop);
        if (found != null) {
          if (loopNode == null) {
            loopNode=createTreeNode;
            loopNode.setLoop(true);
            loopNode.setOptional(foxNode.isOptional());
          }
        }
      }
      if (found == null) {
        continue;
      }
 else {
        xpathAndOrder.put(createTreeNode.getXpath(),found.getOrder());
        Integer index=null;
        List<TreeNode> children=parent.getChildren();
        for (int i=0; i < children.size(); i++) {
          Integer order=xpathAndOrder.get(children.get(i).getXpath());
          if (found.getOrder() < order) {
            index=i;
          }
        }
        if (index == null) {
          parent.getChildren().add(createTreeNode);
        }
 else {
          parent.getChildren().add(index,createTreeNode);
        }
      }
    }
    prepareModelFromOutput(foxNode.getChildren(),createTreeNode);
  }
}