Program: 124284
Project: 124284
Buggy source:
public void rebuildInputTree(InputXmlTree inputTree,IMetadataTable metadataTable,XmlMapData mapData){
  if (metadataTable != null && metadataTable.getListColumns() != null) {
    List<IMetadataColumn> listColumns=metadataTable.getListColumns();
    EList<TreeNode> nodes=inputTree.getNodes();
    for (int i=0; i < listColumns.size(); i++) {
      IMetadataColumn column=listColumns.get(i);
      TreeNode found=null;
      int j=0;
      for (; j < nodes.size(); j++) {
        TreeNode node=nodes.get(j);
        if (node.getName() != null && node.getName().equals(column.getLabel())) {
          found=node;
          break;
        }
      }
      if (found != null) {
        found.setType(column.getTalendType());
        if (i != j) {
          TreeNode temp=nodes.get(j);
          nodes.remove(j);
          nodes.add(i,temp);
        }
      }
 else {
        found=XmlmapFactory.eINSTANCE.createTreeNode();
        found.setName(column.getLabel());
        found.setType(column.getTalendType());
        found.setNullable(column.isNullable());
        found.setXpath(XmlMapUtil.getXPath(inputTree.getName(),found.getName(),found.getNodeType()));
        nodes.add(i,found);
      }
      if (XmlMapUtil.DOCUMENT.equals(found.getType())) {
        EList<TreeNode> children=found.getChildren();
        if (children.isEmpty()) {
          XmlMapUtil.detachConnectionsTarget(found,mapData);
          TreeNode treeRoot=XmlmapFactory.eINSTANCE.createTreeNode();
          treeRoot.setName("String_Node_Str");
          treeRoot.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
          treeRoot.setNodeType(NodeType.ELEMENT);
          treeRoot.setXpath(XmlMapUtil.getXPath(found.getXpath(),treeRoot.getName(),treeRoot.getNodeType()));
          children.add(treeRoot);
        }
      }
 else {
        EList<TreeNode> children=found.getChildren();
        if (!children.isEmpty()) {
          XmlMapUtil.detachConnectionsTarget(found,mapData);
          found.getChildren().clear();
        }
      }
    }
    if (nodes.size() > listColumns.size()) {
      List unUsed=new ArrayList();
      for (int i=listColumns.size(); i < nodes.size(); i++) {
        XmlMapUtil.detachConnectionsTarget(nodes.get(i),mapData);
        unUsed.add(nodes.get(i));
      }
      nodes.removeAll(unUsed);
    }
  }
  if (inputTree.isLookup()) {
    rebuildInputNodesConnections(inputTree.getNodes(),mapData);
  }
}

Fixed version (ground truth):
public void rebuildInputTree(InputXmlTree inputTree,IMetadataTable metadataTable,XmlMapData mapData){
  if (metadataTable != null && metadataTable.getListColumns() != null) {
    List<IMetadataColumn> listColumns=metadataTable.getListColumns();
    EList<TreeNode> nodes=inputTree.getNodes();
    for (int i=0; i < listColumns.size(); i++) {
      IMetadataColumn column=listColumns.get(i);
      TreeNode found=null;
      int j=0;
      for (; j < nodes.size(); j++) {
        TreeNode node=nodes.get(j);
        if (node.getName() != null && node.getName().equals(column.getLabel())) {
          found=node;
          break;
        }
      }
      if (found != null) {
        found.setType(column.getTalendType());
        if (i != j) {
          TreeNode temp=nodes.get(j);
          nodes.remove(j);
          nodes.add(i,temp);
        }
      }
 else {
        found=XmlmapFactory.eINSTANCE.createTreeNode();
        found.setName(column.getLabel());
        found.setType(column.getTalendType());
        found.setNullable(column.isNullable());
        found.setXpath(XmlMapUtil.getXPath(inputTree.getName(),found.getName(),found.getNodeType()));
        nodes.add(i,found);
      }
      if (XmlMapUtil.DOCUMENT.equals(found.getType())) {
        EList<TreeNode> children=found.getChildren();
        if (children.isEmpty()) {
          XmlMapUtil.detachNodeConnections(found,mapData,true);
          TreeNode treeRoot=XmlmapFactory.eINSTANCE.createTreeNode();
          treeRoot.setName("String_Node_Str");
          treeRoot.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
          treeRoot.setNodeType(NodeType.ELEMENT);
          treeRoot.setXpath(XmlMapUtil.getXPath(found.getXpath(),treeRoot.getName(),treeRoot.getNodeType()));
          children.add(treeRoot);
        }
      }
 else {
        EList<TreeNode> children=found.getChildren();
        if (!children.isEmpty()) {
          XmlMapUtil.detachNodeConnections(found,mapData,true);
          found.getChildren().clear();
        }
      }
    }
    if (nodes.size() > listColumns.size()) {
      List unUsed=new ArrayList();
      for (int i=listColumns.size(); i < nodes.size(); i++) {
        XmlMapUtil.detachNodeConnections(nodes.get(i),mapData,true);
        unUsed.add(nodes.get(i));
      }
      nodes.removeAll(unUsed);
    }
  }
  if (inputTree.isLookup()) {
    rebuildInputNodesConnections(inputTree.getNodes(),mapData);
  }
}