Program: 144973
Project: 144973
Buggy source:
private void expandReference(TreeReference sourceRef,AbstractTreeElement node,Vector<TreeReference> refs,boolean includeTemplates){
  int depth=node.getDepth();
  Vector<XPathExpression> predicates=null;
  if (depth == sourceRef.size()) {
    refs.addElement(node.getRef());
  }
 else {
    String name=sourceRef.getName(depth);
    predicates=sourceRef.getPredicate(depth);
    int mult=sourceRef.getMultiplicity(depth);
    Vector<AbstractTreeElement> set=new Vector<AbstractTreeElement>();
    if (node.getNumChildren() > 0) {
      if (mult == TreeReference.INDEX_UNBOUND) {
        int count=node.getChildMultiplicity(name);
        for (int i=0; i < count; i++) {
          AbstractTreeElement child=node.getChild(name,i);
          if (child != null) {
            set.addElement(child);
          }
 else {
            throw new IllegalStateException();
          }
        }
        if (includeTemplates) {
          AbstractTreeElement template=node.getChild(name,TreeReference.INDEX_TEMPLATE);
          if (template != null) {
            set.addElement(template);
          }
        }
      }
 else       if (mult != TreeReference.INDEX_ATTRIBUTE) {
        AbstractTreeElement child=node.getChild(name,mult);
        if (child != null) {
          set.addElement(child);
        }
      }
    }
    if (mult == TreeReference.INDEX_ATTRIBUTE) {
      AbstractTreeElement attribute=node.getAttribute(null,name);
      if (attribute != null) {
        set.addElement(attribute);
      }
    }
    for (Enumeration e=set.elements(); e.hasMoreElements(); ) {
      AbstractTreeElement treeElement=(AbstractTreeElement)e.nextElement();
      if (predicates != null) {
        TreeReference treeRef=treeElement.getRef();
        boolean passedAll=true;
        for (        XPathExpression xpe : predicates) {
          EvaluationContext evalContext=new EvaluationContext(this,treeRef);
          Object o=xpe.eval(instance,evalContext);
          if (o instanceof Boolean) {
            boolean passed=((Boolean)o).booleanValue();
            if (!passed) {
              passedAll=false;
              break;
            }
          }
        }
        if (passedAll) {
          expandReference(sourceRef,treeElement,refs,includeTemplates);
        }
      }
 else {
        expandReference(sourceRef,treeElement,refs,includeTemplates);
      }
    }
  }
}

Fixed version (ground truth):
private void expandReference(TreeReference sourceRef,AbstractTreeElement node,Vector<TreeReference> refs,boolean includeTemplates){
  int depth=node.getDepth();
  Vector<XPathExpression> predicates=null;
  if (depth == sourceRef.size()) {
    refs.addElement(node.getRef());
  }
 else {
    String name=sourceRef.getName(depth);
    predicates=sourceRef.getPredicate(depth);
    int mult=sourceRef.getMultiplicity(depth);
    Vector<AbstractTreeElement> set=new Vector<AbstractTreeElement>();
    if (node.hasChildren()) {
      if (mult == TreeReference.INDEX_UNBOUND) {
        int count=node.getChildMultiplicity(name);
        for (int i=0; i < count; i++) {
          AbstractTreeElement child=node.getChild(name,i);
          if (child != null) {
            set.addElement(child);
          }
 else {
            throw new IllegalStateException();
          }
        }
        if (includeTemplates) {
          AbstractTreeElement template=node.getChild(name,TreeReference.INDEX_TEMPLATE);
          if (template != null) {
            set.addElement(template);
          }
        }
      }
 else       if (mult != TreeReference.INDEX_ATTRIBUTE) {
        AbstractTreeElement child=node.getChild(name,mult);
        if (child != null) {
          set.addElement(child);
        }
      }
    }
    if (mult == TreeReference.INDEX_ATTRIBUTE) {
      AbstractTreeElement attribute=node.getAttribute(null,name);
      if (attribute != null) {
        set.addElement(attribute);
      }
    }
    for (Enumeration e=set.elements(); e.hasMoreElements(); ) {
      AbstractTreeElement treeElement=(AbstractTreeElement)e.nextElement();
      if (predicates != null) {
        TreeReference treeRef=treeElement.getRef();
        boolean passedAll=true;
        for (        XPathExpression xpe : predicates) {
          EvaluationContext evalContext=new EvaluationContext(this,treeRef);
          Object o=xpe.eval(instance,evalContext);
          if (o instanceof Boolean) {
            boolean passed=((Boolean)o).booleanValue();
            if (!passed) {
              passedAll=false;
              break;
            }
          }
        }
        if (passedAll) {
          expandReference(sourceRef,treeElement,refs,includeTemplates);
        }
      }
 else {
        expandReference(sourceRef,treeElement,refs,includeTemplates);
      }
    }
  }
}