Program: 117924
Project: 117924
Buggy source:
private void prepareEmfTreeFromConnection(XmlFileConnection connection){
  schemaNode.getChildren().clear();
  EList root=connection.getRoot();
  EList loop=connection.getLoop();
  EList group=connection.getGroup();
  TreeNode rootNode=null;
  TreeNode current=null;
  TreeNode temp=null;
  TreeNode mainNode=null;
  String mainPath=null;
  String currentPath="String_Node_Str";
  String defaultValue=null;
  for (int i=0; i < root.size(); i++) {
    XMLFileNode node=(XMLFileNode)root.get(i);
    String newPath=node.getXMLPath();
    defaultValue=node.getDefaultValue();
    String type=node.getType();
    if (node.getAttribute().equals("String_Node_Str")) {
      this.addAttributeNamespace(current,currentPath,newPath,type,NodeType.ATTRIBUT,defaultValue);
    }
 else     if (node.getAttribute().equals("String_Node_Str")) {
      this.addAttributeNamespace(current,currentPath,newPath,type,NodeType.NAME_SPACE,defaultValue);
    }
 else {
      temp=this.addElement(current,currentPath,newPath,type,NodeType.ELEMENT,node.getOrder());
      if (rootNode == null) {
        rootNode=temp;
      }
      if (node.getAttribute().equals("String_Node_Str")) {
        temp.setMain(true);
        mainNode=temp;
        mainPath=newPath;
      }
      current=temp;
      currentPath=newPath;
    }
  }
  current=mainNode;
  currentPath=mainPath;
  boolean isFirst=true;
  groupElements=new ArrayList<TreeNode>();
  for (int i=0; i < group.size(); i++) {
    XMLFileNode node=(XMLFileNode)group.get(i);
    String newPath=node.getXMLPath();
    defaultValue=node.getDefaultValue();
    String type=node.getType();
    if (node.getAttribute().equals("String_Node_Str")) {
      this.addAttributeNamespace(current,currentPath,newPath,type,NodeType.ATTRIBUT,defaultValue);
    }
 else     if (node.getAttribute().equals("String_Node_Str")) {
      this.addAttributeNamespace(current,currentPath,newPath,type,NodeType.NAME_SPACE,defaultValue);
    }
 else {
      temp=this.addElement(current,currentPath,newPath,type,NodeType.ELEMENT,node.getOrder());
      groupElements.add(temp);
      if (node.getAttribute().equals("String_Node_Str")) {
        temp.setMain(true);
        mainNode=temp;
        mainPath=newPath;
      }
      current=temp;
      currentPath=newPath;
    }
  }
  current=mainNode;
  currentPath=mainPath;
  isFirst=true;
  for (int i=0; i < loop.size(); i++) {
    XMLFileNode node=(XMLFileNode)loop.get(i);
    String newPath=node.getXMLPath();
    defaultValue=node.getDefaultValue();
    String type=node.getType();
    if (node.getAttribute().equals("String_Node_Str")) {
      this.addAttributeNamespace(current,currentPath,newPath,type,NodeType.ATTRIBUT,defaultValue);
    }
 else     if (node.getAttribute().equals("String_Node_Str")) {
      this.addAttributeNamespace(current,currentPath,newPath,type,NodeType.NAME_SPACE,defaultValue);
    }
 else {
      temp=this.addElement(current,currentPath,newPath,type,NodeType.ELEMENT,node.getOrder());
      if (rootNode == null) {
        rootNode=temp;
      }
      if (node.getAttribute().equals("String_Node_Str")) {
        temp.setMain(true);
        mainNode=temp;
        mainPath=newPath;
      }
      if (isFirst) {
        temp.setLoop(true);
        loopNode=temp;
        isFirst=false;
      }
      current=temp;
      currentPath=newPath;
    }
  }
  if (rootNode != null) {
    schemaNode.getChildren().add(rootNode);
  }
  if (loopNode != null) {
    fillGroup(loopNode,groupElements);
  }
}

Fixed version (ground truth):
private void prepareEmfTreeFromConnection(XmlFileConnection connection){
  schemaNode.getChildren().clear();
  EList root=connection.getRoot();
  EList loop=connection.getLoop();
  EList group=connection.getGroup();
  TreeNode rootNode=null;
  TreeNode current=null;
  TreeNode temp=null;
  TreeNode mainNode=null;
  String mainPath=null;
  String currentPath="String_Node_Str";
  String defaultValue=null;
  MetadataTable metaTable=ConnectionHelper.getTables(connection).toArray(new MetadataTable[0])[0];
  for (int i=0; i < root.size(); i++) {
    XMLFileNode node=(XMLFileNode)root.get(i);
    String newPath=node.getXMLPath();
    defaultValue=node.getDefaultValue();
    String type=node.getType();
    if (node.getAttribute().equals("String_Node_Str")) {
      this.addAttributeNamespace(current,currentPath,newPath,type,NodeType.ATTRIBUT,defaultValue);
    }
 else     if (node.getAttribute().equals("String_Node_Str")) {
      this.addAttributeNamespace(current,currentPath,newPath,type,NodeType.NAME_SPACE,defaultValue);
    }
 else {
      String columnPattern=getColumnPatternFromMetadataTable(node,metaTable);
      temp=this.addElement(current,currentPath,newPath,type,columnPattern,NodeType.ELEMENT,node.getOrder());
      if (rootNode == null) {
        rootNode=temp;
      }
      if (node.getAttribute().equals("String_Node_Str")) {
        temp.setMain(true);
        mainNode=temp;
        mainPath=newPath;
      }
      current=temp;
      currentPath=newPath;
    }
  }
  current=mainNode;
  currentPath=mainPath;
  boolean isFirst=true;
  groupElements=new ArrayList<TreeNode>();
  for (int i=0; i < group.size(); i++) {
    XMLFileNode node=(XMLFileNode)group.get(i);
    String newPath=node.getXMLPath();
    defaultValue=node.getDefaultValue();
    String type=node.getType();
    if (node.getAttribute().equals("String_Node_Str")) {
      this.addAttributeNamespace(current,currentPath,newPath,type,NodeType.ATTRIBUT,defaultValue);
    }
 else     if (node.getAttribute().equals("String_Node_Str")) {
      this.addAttributeNamespace(current,currentPath,newPath,type,NodeType.NAME_SPACE,defaultValue);
    }
 else {
      String columnPattern=getColumnPatternFromMetadataTable(node,metaTable);
      temp=this.addElement(current,currentPath,newPath,type,columnPattern,NodeType.ELEMENT,node.getOrder());
      groupElements.add(temp);
      if (node.getAttribute().equals("String_Node_Str")) {
        temp.setMain(true);
        mainNode=temp;
        mainPath=newPath;
      }
      current=temp;
      currentPath=newPath;
    }
  }
  current=mainNode;
  currentPath=mainPath;
  isFirst=true;
  for (int i=0; i < loop.size(); i++) {
    XMLFileNode node=(XMLFileNode)loop.get(i);
    String newPath=node.getXMLPath();
    defaultValue=node.getDefaultValue();
    String type=node.getType();
    if (node.getAttribute().equals("String_Node_Str")) {
      this.addAttributeNamespace(current,currentPath,newPath,type,NodeType.ATTRIBUT,defaultValue);
    }
 else     if (node.getAttribute().equals("String_Node_Str")) {
      this.addAttributeNamespace(current,currentPath,newPath,type,NodeType.NAME_SPACE,defaultValue);
    }
 else {
      String columnPattern=getColumnPatternFromMetadataTable(node,metaTable);
      temp=this.addElement(current,currentPath,newPath,type,columnPattern,NodeType.ELEMENT,node.getOrder());
      if (rootNode == null) {
        rootNode=temp;
      }
      if (node.getAttribute().equals("String_Node_Str")) {
        temp.setMain(true);
        mainNode=temp;
        mainPath=newPath;
      }
      if (isFirst) {
        temp.setLoop(true);
        loopNode=temp;
        isFirst=false;
      }
      current=temp;
      currentPath=newPath;
    }
  }
  if (rootNode != null) {
    schemaNode.getChildren().add(rootNode);
  }
  if (loopNode != null) {
    fillGroup(loopNode,groupElements);
  }
}