Program: 147747
Project: 147747
Buggy source:
private Object[] getExpandedTypeElements(DataModelMainPage mainPage){
  TreeViewer typesViewer=mainPage.getTypesViewer();
  SchemaTreeContentProvider contentProvider=(SchemaTreeContentProvider)typesViewer.getContentProvider();
  Object[] xsdDeclarations=getChildren(contentProvider.getXsdSchema(),contentProvider);
  List<Object> result=new ArrayList<Object>();
  Deque<XSDNode> nodeStack=new LinkedList<XSDNode>();
  Deque<Object> elementStack=new LinkedList<Object>();
  Map<XSDNode,XSDTypeDefinition> expandedRoots=new HashMap<XSDNode,XSDTypeDefinition>();
  for (  Object obj : xsdDeclarations) {
    XSDTypeDefinition type=(XSDTypeDefinition)obj;
    String name=type.getName();
    for (    XSDNode node : expandedTypes) {
      if (name.equals(((XSDTypeDefinition)node.data).getName())) {
        expandedRoots.put(node,type);
        result.add(type);
        nodeStack.add(node);
        elementStack.add(type);
        break;
      }
    }
  }
  while (!nodeStack.isEmpty() && !elementStack.isEmpty()) {
    XSDNode node=nodeStack.pollFirst();
    Object element=elementStack.pollFirst();
    List<XSDNode> nodes=node.childs;
    Object[] elementChildren=getChildren(element,contentProvider);
    if (nodes != null && nodes.size() > 0 && elementChildren != null) {
      Map<XSDNode,Object> nodeElementPairs=getNodeElementPairs(elementChildren,nodes);
      for (      XSDNode node2 : nodeElementPairs.keySet()) {
        nodeStack.add(node2);
        elementStack.add(nodeElementPairs.get(node2));
        result.add(nodeElementPairs.get(node2));
      }
    }
  }
  return result.toArray();
}

Fixed version (ground truth):
private Object[] getExpandedTypeElements(DataModelMainPage mainPage){
  TreeViewer typesViewer=mainPage.getTypesViewer();
  SchemaTreeContentProvider contentProvider=(SchemaTreeContentProvider)typesViewer.getContentProvider();
  Object[] xsdDeclarations=getChildren(contentProvider.getXsdSchema(),contentProvider);
  List<Object> result=new ArrayList<Object>();
  Deque<ExpandInfoNode> nodeStack=new LinkedList<ExpandInfoNode>();
  Deque<Object> elementStack=new LinkedList<Object>();
  Map<ExpandInfoNode,XSDTypeDefinition> expandedRoots=new HashMap<ExpandInfoNode,XSDTypeDefinition>();
  for (  Object obj : xsdDeclarations) {
    XSDTypeDefinition type=(XSDTypeDefinition)obj;
    String name=type.getName();
    for (    ExpandInfoNode node : expandedTypes) {
      if (name.equals(node.name)) {
        expandedRoots.put(node,type);
        result.add(type);
        nodeStack.add(node);
        elementStack.add(type);
        break;
      }
    }
  }
  while (!nodeStack.isEmpty() && !elementStack.isEmpty()) {
    ExpandInfoNode node=nodeStack.pollFirst();
    Object element=elementStack.pollFirst();
    List<ExpandInfoNode> nodes=node.childs;
    Object[] elementChildren=getChildren(element,contentProvider);
    if (nodes != null && nodes.size() > 0 && elementChildren != null) {
      Map<ExpandInfoNode,Object> nodeElementPairs=getNodeElementPairs(elementChildren,nodes);
      for (      ExpandInfoNode node2 : nodeElementPairs.keySet()) {
        nodeStack.add(node2);
        elementStack.add(nodeElementPairs.get(node2));
        result.add(nodeElementPairs.get(node2));
      }
    }
  }
  return result.toArray();
}