Program: 123318
Project: 123318
Buggy source:
protected TreeNode addElement(TreeNode lastTreeNode,String lastXmlPath,XMLFileNode xmlFilenode){
  String newPath=xmlFilenode.getXMLPath();
  String defaultValue=xmlFilenode.getDefaultValue();
  String name=newPath.substring(newPath.lastIndexOf("String_Node_Str") + 1);
  String parentPath=newPath.substring(0,newPath.lastIndexOf("String_Node_Str"));
  TreeNode temp=createModel();
  temp.setName(name);
  temp.setDefaultValue(defaultValue);
  temp.setNodeType(NodeType.ELEMENT);
  if (lastTreeNode == parentNode) {
    temp.setXpath(XmlMapUtil.getXPath(lastTreeNode.getXpath(),temp.getName(),temp.getNodeType()));
    return temp;
  }
  if (lastXmlPath.equals(parentPath)) {
    temp.setXpath(XmlMapUtil.getXPath(lastTreeNode.getXpath(),temp.getName(),temp.getNodeType()));
    EList<TreeNode> children=lastTreeNode.getChildren();
    int childrenSize=children.size();
    int index=childrenSize;
    int order=xmlFilenode.getOrder();
    for (int i=0; i < childrenSize; i++) {
      TreeNode treeNode=children.get(i);
      XMLFileNode xmlFileNode=nodeMap.get(treeNode);
      if (xmlFileNode != null) {
        if (order < xmlFileNode.getOrder()) {
          index=children.indexOf(treeNode);
          break;
        }
      }
    }
    if (index == childrenSize) {
      children.add(temp);
    }
 else {
      children.add(index,temp);
    }
    nodeMap.put(temp,xmlFilenode);
  }
 else {
    String[] nods=lastXmlPath.split("String_Node_Str");
    String[] newNods=parentPath.split("String_Node_Str");
    int parentLevel=0;
    int checkLength=nods.length < newNods.length ? nods.length : newNods.length;
    for (int i=1; i < checkLength; i++) {
      if (nods[i].equals(newNods[i])) {
        parentLevel=i;
      }
    }
    TreeNode parent=lastTreeNode;
    for (int i=0; i < nods.length - (parentLevel + 1); i++) {
      TreeNode tmpParent=(TreeNode)parent.eContainer();
      if (tmpParent == null) {
        break;
      }
      parent=tmpParent;
    }
    if (parent != null) {
      temp.setXpath(XmlMapUtil.getXPath(parent.getXpath(),temp.getName(),temp.getNodeType()));
      EList<TreeNode> children=parent.getChildren();
      int childrenSize=children.size();
      int index=childrenSize - 1;
      int order=xmlFilenode.getOrder();
      for (int i=0; i < childrenSize; i++) {
        TreeNode treeNode=children.get(i);
        XMLFileNode xmlFileNode=nodeMap.get(treeNode);
        if (xmlFileNode != null) {
          if (order < xmlFileNode.getOrder()) {
            index=children.indexOf(treeNode);
            break;
          }
        }
      }
      if (index == childrenSize - 1) {
        children.add(temp);
      }
 else {
        children.add(index,temp);
      }
      nodeMap.put(temp,xmlFilenode);
    }
  }
  return temp;
}

Fixed version (ground truth):
protected TreeNode addElement(TreeNode lastTreeNode,String lastXmlPath,XMLFileNode xmlFilenode){
  String newPath=xmlFilenode.getXMLPath();
  String defaultValue=xmlFilenode.getDefaultValue();
  String name=newPath.substring(newPath.lastIndexOf("String_Node_Str") + 1);
  String parentPath=newPath.substring(0,newPath.lastIndexOf("String_Node_Str"));
  TreeNode temp=createModel();
  temp.setName(name);
  temp.setDefaultValue(defaultValue);
  temp.setNodeType(NodeType.ELEMENT);
  if (lastTreeNode == schemaNode) {
    temp.setXpath(XmlMapUtil.getXPath(lastTreeNode.getXpath(),temp.getName(),temp.getNodeType()));
    return temp;
  }
  if (lastXmlPath.equals(parentPath)) {
    temp.setXpath(XmlMapUtil.getXPath(lastTreeNode.getXpath(),temp.getName(),temp.getNodeType()));
    EList<TreeNode> children=lastTreeNode.getChildren();
    int childrenSize=children.size();
    int index=childrenSize;
    int order=xmlFilenode.getOrder();
    for (int i=0; i < childrenSize; i++) {
      TreeNode treeNode=children.get(i);
      XMLFileNode xmlFileNode=nodeMap.get(treeNode);
      if (xmlFileNode != null) {
        if (order < xmlFileNode.getOrder()) {
          index=children.indexOf(treeNode);
          break;
        }
      }
    }
    if (index == childrenSize) {
      children.add(temp);
    }
 else {
      children.add(index,temp);
    }
    nodeMap.put(temp,xmlFilenode);
  }
 else {
    String[] nods=lastXmlPath.split("String_Node_Str");
    String[] newNods=parentPath.split("String_Node_Str");
    int parentLevel=0;
    int checkLength=nods.length < newNods.length ? nods.length : newNods.length;
    for (int i=1; i < checkLength; i++) {
      if (nods[i].equals(newNods[i])) {
        parentLevel=i;
      }
    }
    TreeNode parent=lastTreeNode;
    for (int i=0; i < nods.length - (parentLevel + 1); i++) {
      TreeNode tmpParent=(TreeNode)parent.eContainer();
      if (tmpParent == null) {
        break;
      }
      parent=tmpParent;
    }
    if (parent != null) {
      temp.setXpath(XmlMapUtil.getXPath(parent.getXpath(),temp.getName(),temp.getNodeType()));
      EList<TreeNode> children=parent.getChildren();
      int childrenSize=children.size();
      int index=childrenSize - 1;
      int order=xmlFilenode.getOrder();
      for (int i=0; i < childrenSize; i++) {
        TreeNode treeNode=children.get(i);
        XMLFileNode xmlFileNode=nodeMap.get(treeNode);
        if (xmlFileNode != null) {
          if (order < xmlFileNode.getOrder()) {
            index=children.indexOf(treeNode);
            break;
          }
        }
      }
      if (index == childrenSize - 1) {
        children.add(temp);
      }
 else {
        children.add(index,temp);
      }
      nodeMap.put(temp,xmlFilenode);
    }
  }
  return temp;
}