Program: 123771
Project: 123771
Buggy source:
public void rebuildModelOutputs(List<IMetadataTable> outputMetadataTables,XmlMapData mapData){
  for (  IMetadataTable meatadataTable : outputMetadataTables) {
    String name=meatadataTable.getTableName();
    OutputXmlTree outputTree=null;
    for (    OutputXmlTree out : mapData.getOutputTrees()) {
      if (out.getName() != null && out.getName().equals(name)) {
        outputTree=out;
        break;
      }
    }
    if (outputTree == null) {
      outputTree=XmlmapFactory.eINSTANCE.createOutputXmlTree();
      outputTree.setName(name);
      mapData.getOutputTrees().add(outputTree);
    }
    List<IMetadataColumn> listColumns=meatadataTable.getListColumns();
    if (listColumns != null) {
      EList<OutputTreeNode> nodes=outputTree.getNodes();
      for (int i=0; i < listColumns.size(); i++) {
        IMetadataColumn column=listColumns.get(i);
        OutputTreeNode found=null;
        int j=0;
        for (; j < nodes.size(); j++) {
          OutputTreeNode 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) {
            OutputTreeNode temp=nodes.get(j);
            nodes.remove(j);
            nodes.add(i,temp);
          }
        }
 else {
          found=XmlmapFactory.eINSTANCE.createOutputTreeNode();
          found.setName(column.getLabel());
          found.setType(column.getTalendType());
          found.setNullable(column.isNullable());
          found.setXpath(XmlMapUtil.getXPath(outputTree.getName(),found.getName(),found.getNodeType()));
          nodes.add(i,found);
        }
        if (XmlMapUtil.DOCUMENT.equals(found.getType())) {
          EList<TreeNode> children=found.getChildren();
          if (children.isEmpty()) {
            XmlMapUtil.detachConnectionsSouce(found,mapData);
            TreeNode treeRoot=XmlmapFactory.eINSTANCE.createOutputTreeNode();
            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++) {
          OutputTreeNode node=nodes.get(i);
          XmlMapUtil.detachConnectionsSouce(node,mapData);
          unUsed.add(node);
        }
        nodes.removeAll(unUsed);
      }
    }
    mapData.getOutputTrees().add(outputTree);
    rebuildOutputNodesConnections(outputTree.getNodes(),mapData);
  }
}

Fixed version (ground truth):
public void rebuildModelOutputs(List<IMetadataTable> outputMetadataTables,XmlMapData mapData){
  for (  IMetadataTable meatadataTable : outputMetadataTables) {
    String name=meatadataTable.getTableName();
    OutputXmlTree outputTree=null;
    for (    OutputXmlTree out : mapData.getOutputTrees()) {
      if (out.getName() != null && out.getName().equals(name)) {
        outputTree=out;
        break;
      }
    }
    if (outputTree == null) {
      outputTree=XmlmapFactory.eINSTANCE.createOutputXmlTree();
      outputTree.setName(name);
      mapData.getOutputTrees().add(outputTree);
    }
    List<IMetadataColumn> listColumns=meatadataTable.getListColumns();
    if (listColumns != null) {
      EList<OutputTreeNode> nodes=outputTree.getNodes();
      for (int i=0; i < listColumns.size(); i++) {
        IMetadataColumn column=listColumns.get(i);
        OutputTreeNode found=null;
        int j=0;
        for (; j < nodes.size(); j++) {
          OutputTreeNode 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) {
            OutputTreeNode temp=nodes.get(j);
            nodes.remove(j);
            nodes.add(i,temp);
          }
        }
 else {
          found=XmlmapFactory.eINSTANCE.createOutputTreeNode();
          found.setName(column.getLabel());
          found.setType(column.getTalendType());
          found.setNullable(column.isNullable());
          found.setXpath(XmlMapUtil.getXPath(outputTree.getName(),found.getName(),found.getNodeType()));
          nodes.add(i,found);
        }
        if (XmlMapUtil.DOCUMENT.equals(found.getType())) {
          EList<TreeNode> children=found.getChildren();
          if (children.isEmpty()) {
            XmlMapUtil.detachConnectionsSouce(found,mapData);
            TreeNode treeRoot=XmlmapFactory.eINSTANCE.createOutputTreeNode();
            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()));
            treeRoot.setLoop(true);
            treeRoot.setMain(true);
            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++) {
          OutputTreeNode node=nodes.get(i);
          XmlMapUtil.detachConnectionsSouce(node,mapData);
          unUsed.add(node);
        }
        nodes.removeAll(unUsed);
      }
    }
    mapData.getOutputTrees().add(outputTree);
    rebuildOutputNodesConnections(outputTree.getNodes(),mapData);
  }
}