Program: 147745
Project: 147745
Buggy source:
private Object[] getExpandedEntityElements(DataModelMainPage mainPage){
  TreeViewer elementsViewer=mainPage.getElementsViewer();
  SchemaTreeContentProvider contentProvider=(SchemaTreeContentProvider)elementsViewer.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,XSDElementDeclaration> expandedRoots=new HashMap<XSDNode,XSDElementDeclaration>();
  for (  Object obj : xsdDeclarations) {
    XSDElementDeclaration decl=(XSDElementDeclaration)obj;
    String name=decl.getName();
    for (    XSDNode node : expandedElements) {
      if (name.equals(((XSDElementDeclaration)node.data).getName())) {
        expandedRoots.put(node,decl);
        result.add(decl);
        nodeStack.add(node);
        elementStack.add(decl);
        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[] getExpandedEntityElements(DataModelMainPage mainPage){
  TreeViewer elementsViewer=mainPage.getElementsViewer();
  SchemaTreeContentProvider contentProvider=(SchemaTreeContentProvider)elementsViewer.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,XSDElementDeclaration> expandedRoots=new HashMap<ExpandInfoNode,XSDElementDeclaration>();
  for (  Object obj : xsdDeclarations) {
    XSDElementDeclaration decl=(XSDElementDeclaration)obj;
    String name=decl.getName();
    for (    ExpandInfoNode node : expandedElements) {
      if (name.equals(node.name)) {
        expandedRoots.put(node,decl);
        result.add(decl);
        nodeStack.add(node);
        elementStack.add(decl);
        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();
}