Program: 119847
Project: 119847
Buggy source:
private void initXmlTreeData(List<String> schemaList,List<HL7FileNode> root,List<HL7TreeNode> treeData){
  Map<String,HL7TreeNode> mapNodes=new HashMap<String,HL7TreeNode>();
  if (hl7ui != null) {
    if (hl7ui.gethl7Manager() instanceof HL7OutputManager) {
      ((HL7OutputManager)hl7ui.gethl7Manager()).getContents().clear();
    }
  }
  HL7TreeNode rootNode=null;
  for (  String rowName : schemaList) {
    HL7TreeNode current=null;
    HL7TreeNode temp=null;
    HL7TreeNode mainNode=null;
    String mainPath=null;
    String currentPath=null;
    String defaultValue=null;
    int nodeOrder=0;
    boolean haveOrder=true;
    String schemaId=rowName + "String_Node_Str";
    for (int i=0; i < root.size(); i++) {
      HL7FileNode node=(HL7FileNode)root.get(i);
      String newPath=node.getFilePath();
      defaultValue=node.getDefaultValue();
      String columnName=node.getRelatedColumn();
      String orderValue=String.valueOf(node.getOrder());
      if (orderValue == null || "String_Node_Str".equals(orderValue)) {
        haveOrder=false;
      }
      if (haveOrder) {
        nodeOrder=node.getOrder();
      }
      String flag=columnName + "String_Node_Str";
      if (columnName != null && columnName.length() > 0 && !flag.startsWith(schemaId)) {
        continue;
      }
      if (node.getAttribute().equals("String_Node_Str")) {
        temp=new Attribute(newPath);
        temp.setDefaultValue(defaultValue);
        temp.setAttribute(true);
        current.addChild(temp);
      }
 else       if (node.getAttribute().equals("String_Node_Str")) {
        temp=new NameSpaceNode(newPath);
        temp.setDefaultValue(defaultValue);
        temp.setNameSpace(true);
        current.addChild(temp);
      }
 else {
        temp=this.addElement(current,currentPath,newPath,defaultValue,mapNodes);
        if (rootNode == null) {
          rootNode=temp;
        }
        if (node.getAttribute().equals("String_Node_Str")) {
          temp.setMain(true);
          mainNode=temp;
          mainPath=newPath;
        }
        current=temp;
        currentPath=newPath;
      }
      if (haveOrder) {
        temp.setOrder(nodeOrder);
      }
      if (columnName != null && columnName.length() > 0) {
        temp.setRow(rowName);
      }
      if (columnName != null && columnName.length() > 0 && columnName.startsWith(schemaId)) {
        columnName=columnName.replace(schemaId,"String_Node_Str");
      }
    }
    if (rootNode == null) {
      rootNode=new Element("String_Node_Str");
    }
    if (haveOrder) {
      orderNode(rootNode);
    }
  }
  if (rootNode != null) {
    treeData.add(rootNode);
  }
  if (hl7ui != null) {
    if (hl7ui.gethl7Manager() instanceof HL7OutputManager) {
      ((HL7OutputManager)hl7ui.gethl7Manager()).getContents().put(rootNode.getColumnLabel(),treeData);
    }
  }
 else   if (form != null) {
    for (    HL7TreeNode hl7Node : treeData) {
      form.getContents().put(rootNode.getColumnLabel(),hl7Node);
    }
  }
}

Fixed version (ground truth):
private void initXmlTreeData(List<String> schemaList,List<HL7FileNode> root,List<HL7TreeNode> treeData){
  Map<String,HL7TreeNode> mapNodes=new HashMap<String,HL7TreeNode>();
  List<? extends IConnection> incomingConnections=new ArrayList<IConnection>();
  if (hl7ui != null) {
    if (hl7ui.gethl7Manager() instanceof HL7OutputManager) {
      ((HL7OutputManager)hl7ui.gethl7Manager()).getContents().clear();
      incomingConnections=NodeUtil.getIncomingConnections(hl7ui.gethl7Manager().getHl7Component(),IConnectionCategory.FLOW);
    }
  }
  HL7TreeNode rootNode=null;
  for (  String rowName : schemaList) {
    IMetadataTable metadataTable=null;
    for (    IConnection connection : incomingConnections) {
      if (connection.getUniqueName().equals(rowName)) {
        metadataTable=connection.getMetadataTable();
        metadataTable.setLabel(connection.getUniqueName());
      }
    }
    HL7TreeNode current=null;
    HL7TreeNode temp=null;
    HL7TreeNode mainNode=null;
    String mainPath=null;
    String currentPath=null;
    String defaultValue=null;
    int nodeOrder=0;
    boolean haveOrder=true;
    String schemaId=rowName + "String_Node_Str";
    for (int i=0; i < root.size(); i++) {
      HL7FileNode node=(HL7FileNode)root.get(i);
      String newPath=node.getFilePath();
      defaultValue=node.getDefaultValue();
      String columnName=node.getRelatedColumn();
      String orderValue=String.valueOf(node.getOrder());
      if (orderValue == null || "String_Node_Str".equals(orderValue)) {
        haveOrder=false;
      }
      if (haveOrder) {
        nodeOrder=node.getOrder();
      }
      String flag=columnName + "String_Node_Str";
      if (columnName != null && columnName.length() > 0 && !flag.startsWith(schemaId)) {
        continue;
      }
      if (node.getAttribute().equals("String_Node_Str")) {
        temp=new Attribute(newPath);
        temp.setDefaultValue(defaultValue);
        temp.setAttribute(true);
        current.addChild(temp);
      }
 else       if (node.getAttribute().equals("String_Node_Str")) {
        temp=new NameSpaceNode(newPath);
        temp.setDefaultValue(defaultValue);
        temp.setNameSpace(true);
        current.addChild(temp);
      }
 else {
        temp=this.addElement(current,currentPath,newPath,defaultValue,mapNodes);
        if (rootNode == null) {
          rootNode=temp;
        }
        if (node.getAttribute().equals("String_Node_Str")) {
          temp.setMain(true);
          mainNode=temp;
          mainPath=newPath;
        }
        current=temp;
        currentPath=newPath;
      }
      if (haveOrder) {
        temp.setOrder(nodeOrder);
      }
      if (columnName != null && columnName.length() > 0) {
        temp.setRow(rowName);
      }
      if (columnName != null && columnName.length() > 0 && columnName.startsWith(schemaId)) {
        columnName=columnName.replace(schemaId,"String_Node_Str");
        if (metadataTable == null) {
          IMetadataTable metadataTableTemp=null;
          for (          IConnection connection : incomingConnections) {
            metadataTableTemp=connection.getMetadataTable();
            String connectionName=metadataTableTemp.getLabel();
            if (connectionName == null) {
              connectionName=connection.getUniqueName();
            }
            if (columnName.startsWith(connectionName)) {
              break;
            }
          }
          if (metadataTableTemp != null) {
            temp.setColumnName(columnName);
            temp.setColumn(metadataTableTemp.getColumn(columnName));
            temp.setTable(metadataTableTemp);
          }
        }
 else {
          temp.setColumnName(columnName);
          temp.setColumn(metadataTable.getColumn(columnName));
          temp.setTable(metadataTable);
        }
      }
    }
    if (rootNode == null) {
      rootNode=new Element("String_Node_Str");
    }
    if (haveOrder) {
      orderNode(rootNode);
    }
  }
  if (rootNode != null) {
    treeData.add(rootNode);
  }
  if (hl7ui != null) {
    if (hl7ui.gethl7Manager() instanceof HL7OutputManager) {
      ((HL7OutputManager)hl7ui.gethl7Manager()).getContents().put(rootNode.getColumnLabel(),treeData);
    }
  }
 else   if (form != null) {
    for (    HL7TreeNode hl7Node : treeData) {
      form.getContents().put(rootNode.getColumnLabel(),hl7Node);
    }
  }
}