Program: 146738
Project: 146738
Buggy source:
/** 
 * A general purpose method for taking an abstract tree element and attempting to batch fetch its children's predicates through static evaluation. 
 * @param parent The element whose children are being requested
 * @param childAttributeHintMap A mapping of paths which can be evaluated in memory.
 * @param name The name of the children being queried
 * @param mult the multiplicity being queried for (could be undefined)
 * @param predicates the evaluation step predicates which are being processed. NOTE: This vectorwill be modified by this method as a side effect if a predicate was succesfully statically evaluated
 * @param evalContext The current eval context.
 * @return A vector of TreeReferences which contains the nodes matched by predicate expressions.Expressions which result in returned matches will be removed from the predicate collection which is provided
 */
public static Vector<TreeReference> tryBatchChildFetch(AbstractTreeElement parent,Hashtable<XPathPathExpr,Hashtable<String,TreeElement[]>> childAttributeHintMap,String name,int mult,Vector<XPathExpression> predicates,EvaluationContext evalContext){
  if (mult != TreeReference.INDEX_UNBOUND || predicates == null) {
    return null;
  }
  Vector<Integer> toRemove=new Vector<Integer>();
  Vector<TreeReference> selectedChildren=null;
  Vector<String> attributes=null;
  Vector<XPathPathExpr> indices=null;
  Vector<TreeElement> kids=null;
  predicate:   for (int i=0; i < predicates.size(); ++i) {
    XPathExpression xpe=predicates.elementAt(i);
    if (xpe instanceof XPathEqExpr) {
      XPathExpression left=((XPathEqExpr)xpe).a;
      XPathExpression right=((XPathEqExpr)xpe).b;
      if (left instanceof XPathPathExpr && (right instanceof XPathStringLiteral || right instanceof XPathPathExpr)) {
        String literalMatch=null;
        if (right instanceof XPathStringLiteral) {
          literalMatch=((XPathStringLiteral)right).s;
        }
 else         if (right instanceof XPathPathExpr) {
          for (          XPathStep step : ((XPathPathExpr)right).steps) {
            if (step.predicates.length > 0) {
              break;
            }
          }
          try {
            Object o=XPathFuncExpr.unpack(right.eval(evalContext));
            literalMatch=XPathFuncExpr.toString(o);
          }
 catch (          XPathException e) {
            e.printStackTrace();
            break;
          }
        }
        if (childAttributeHintMap != null) {
          if (childAttributeHintMap.containsKey(left)) {
            TreeElement[] children=childAttributeHintMap.get(left).get(literalMatch);
            if (selectedChildren == null) {
              selectedChildren=new Vector<TreeReference>();
            }
            if (children != null) {
              for (              TreeElement element : children) {
                selectedChildren.addElement(element.getRef());
              }
            }
            toRemove.addElement(DataUtil.integer(i));
            continue predicate;
          }
        }
        if (attributes == null) {
          attributes=new Vector<String>();
          indices=new Vector<XPathPathExpr>();
          kids=parent.getChildrenWithName(name);
          if (kids.size() == 0) {
            return null;
          }
          AbstractTreeElement kid=kids.elementAt(0);
          for (int j=0; j < kid.getAttributeCount(); ++j) {
            String attribute=kid.getAttributeName(j);
            XPathPathExpr path=TreeUtilities.getXPathAttrExpression(attribute);
            attributes.addElement(attribute);
            indices.addElement(path);
          }
        }
        for (int j=0; j < indices.size(); ++j) {
          XPathPathExpr expr=indices.elementAt(j);
          if (expr.equals(left)) {
            String attributeName=attributes.elementAt(j);
            for (int kidI=0; kidI < kids.size(); ++kidI) {
              if (kids.elementAt(kidI).getAttributeValue(null,attributeName).equals(literalMatch)) {
                if (selectedChildren == null) {
                  selectedChildren=new Vector<TreeReference>();
                }
                selectedChildren.addElement(kids.elementAt(kidI).getRef());
              }
            }
            toRemove.addElement(DataUtil.integer(i));
            continue predicate;
          }
        }
      }
    }
    break;
  }
  if (selectedChildren == null) {
    return null;
  }
  for (int i=toRemove.size() - 1; i >= 0; i--) {
    predicates.removeElementAt(toRemove.elementAt(i).intValue());
  }
  return selectedChildren;
}

Fixed version (ground truth):
/** 
 * A general purpose method for taking an abstract tree element and attempting to batch fetch its children's predicates through static evaluation. 
 * @param parent The element whose children are being requested
 * @param childAttributeHintMap A mapping of paths which can be evaluated in memory.
 * @param name The name of the children being queried
 * @param mult the multiplicity being queried for (could be undefined)
 * @param predicates the evaluation step predicates which are being processed. NOTE: This vectorwill be modified by this method as a side effect if a predicate was succesfully statically evaluated
 * @param evalContext The current eval context.
 * @return A vector of TreeReferences which contains the nodes matched by predicate expressions.Expressions which result in returned matches will be removed from the predicate collection which is provided
 */
public static Vector<TreeReference> tryBatchChildFetch(AbstractTreeElement parent,Hashtable<XPathPathExpr,Hashtable<String,TreeElement[]>> childAttributeHintMap,String name,int mult,Vector<XPathExpression> predicates,EvaluationContext evalContext){
  if (mult != TreeReference.INDEX_UNBOUND || predicates == null) {
    return null;
  }
  Vector<Integer> toRemove=new Vector<Integer>();
  Vector<TreeReference> allSelectedChildren=null;
  Vector<String> attributes=null;
  Vector<XPathPathExpr> indices=null;
  Vector<TreeElement> kids=null;
  predicate:   for (int i=0; i < predicates.size(); ++i) {
    Vector<TreeReference> predicateMatches=new Vector<TreeReference>();
    XPathExpression xpe=predicates.elementAt(i);
    if (xpe instanceof XPathEqExpr) {
      XPathExpression left=((XPathEqExpr)xpe).a;
      XPathExpression right=((XPathEqExpr)xpe).b;
      if (left instanceof XPathPathExpr && (right instanceof XPathStringLiteral || right instanceof XPathPathExpr)) {
        String literalMatch=null;
        if (right instanceof XPathStringLiteral) {
          literalMatch=((XPathStringLiteral)right).s;
        }
 else         if (right instanceof XPathPathExpr) {
          for (          XPathStep step : ((XPathPathExpr)right).steps) {
            if (step.predicates.length > 0) {
              break;
            }
          }
          try {
            Object o=XPathFuncExpr.unpack(right.eval(evalContext));
            literalMatch=XPathFuncExpr.toString(o);
          }
 catch (          XPathException e) {
            e.printStackTrace();
            break;
          }
        }
        if (childAttributeHintMap != null) {
          if (childAttributeHintMap.containsKey(left)) {
            TreeElement[] children=childAttributeHintMap.get(left).get(literalMatch);
            if (children != null) {
              for (              TreeElement element : children) {
                predicateMatches.addElement(element.getRef());
              }
            }
            allSelectedChildren=merge(allSelectedChildren,predicateMatches,i,toRemove);
            continue predicate;
          }
        }
        if (attributes == null) {
          attributes=new Vector<String>();
          indices=new Vector<XPathPathExpr>();
          kids=parent.getChildrenWithName(name);
          if (kids.size() == 0) {
            return null;
          }
          AbstractTreeElement kid=kids.elementAt(0);
          for (int j=0; j < kid.getAttributeCount(); ++j) {
            String attribute=kid.getAttributeName(j);
            XPathPathExpr path=TreeUtilities.getXPathAttrExpression(attribute);
            attributes.addElement(attribute);
            indices.addElement(path);
          }
        }
        for (int j=0; j < indices.size(); ++j) {
          XPathPathExpr expr=indices.elementAt(j);
          if (expr.equals(left)) {
            String attributeName=attributes.elementAt(j);
            for (int kidI=0; kidI < kids.size(); ++kidI) {
              if (kids.elementAt(kidI).getAttributeValue(null,attributeName).equals(literalMatch)) {
                predicateMatches.addElement(kids.elementAt(kidI).getRef());
              }
            }
            allSelectedChildren=merge(allSelectedChildren,predicateMatches,i,toRemove);
            continue predicate;
          }
        }
      }
    }
    break;
  }
  if (allSelectedChildren == null) {
    return null;
  }
  for (int i=toRemove.size() - 1; i >= 0; i--) {
    predicates.removeElementAt(toRemove.elementAt(i).intValue());
  }
  return allSelectedChildren;
}