Program: 65946
Project: 65946
Buggy source:
protected XPathNode getNonAttributeXPathNode(String namespaceURI,String localName,String qName){
  if (0 == levelIndex) {
    return xPathNode;
  }
  if (namespaceURI != null && namespaceURI.length() == 0) {
    xPathFragment.setLocalName(qName);
    xPathFragment.setNamespaceURI(null);
  }
 else {
    xPathFragment.setLocalName(localName);
    xPathFragment.setNamespaceURI(namespaceURI);
  }
  XPathNode resultNode=null;
  Map nonAttributeChildrenMap=xPathNode.getNonAttributeChildrenMap();
  if (null != nonAttributeChildrenMap) {
    resultNode=(XPathNode)nonAttributeChildrenMap.get(xPathFragment);
    if (null == resultNode) {
      int newIndex;
      if (null == this.indexMap) {
        this.indexMap=new HashMap();
        newIndex=1;
      }
 else {
        Integer oldIndex=indexMap.get(xPathFragment);
        if (null == oldIndex) {
          newIndex=1;
        }
 else {
          newIndex=oldIndex.intValue() + 1;
        }
      }
      indexMap.put(xPathFragment,newIndex);
      XPathFragment positionalFragment=new XPathFragment();
      positionalFragment.setNamespaceURI(xPathFragment.getNamespaceURI());
      positionalFragment.setLocalName(xPathFragment.getLocalName());
      positionalFragment.setIndexValue(newIndex);
      resultNode=(XPathNode)nonAttributeChildrenMap.get(positionalFragment);
      if (null == resultNode) {
        resultNode=xPathNode.getAnyNode();
      }
    }
    return resultNode;
  }
  return null;
}

Fixed version (ground truth):
protected XPathNode getNonAttributeXPathNode(String namespaceURI,String localName,String qName,Attributes attributes){
  if (0 == levelIndex) {
    return xPathNode;
  }
  if (namespaceURI != null && namespaceURI.length() == 0) {
    xPathFragment.setLocalName(qName);
    xPathFragment.setNamespaceURI(null);
  }
 else {
    xPathFragment.setLocalName(localName);
    xPathFragment.setNamespaceURI(namespaceURI);
  }
  XPathNode resultNode=null;
  Map nonAttributeChildrenMap=xPathNode.getNonAttributeChildrenMap();
  if (null != nonAttributeChildrenMap) {
    resultNode=(XPathNode)nonAttributeChildrenMap.get(xPathFragment);
    if (null == resultNode) {
      int newIndex;
      if (null == this.indexMap) {
        this.indexMap=new HashMap();
        newIndex=1;
      }
 else {
        Integer oldIndex=indexMap.get(xPathFragment);
        if (null == oldIndex) {
          newIndex=1;
        }
 else {
          newIndex=oldIndex.intValue() + 1;
        }
      }
      indexMap.put(xPathFragment,newIndex);
      XPathFragment predicateFragment=new XPathFragment();
      predicateFragment.setNamespaceURI(xPathFragment.getNamespaceURI());
      predicateFragment.setLocalName(xPathFragment.getLocalName());
      predicateFragment.setIndexValue(newIndex);
      resultNode=(XPathNode)nonAttributeChildrenMap.get(predicateFragment);
      if (null == resultNode) {
        predicateFragment.setIndexValue(-1);
        for (int x=0, length=attributes.getLength(); x < length; x++) {
          XPathFragment conditionFragment=new XPathFragment();
          conditionFragment.setLocalName(attributes.getLocalName(x));
          conditionFragment.setNamespaceURI(attributes.getURI(x));
          conditionFragment.setAttribute(true);
          XPathPredicate condition=new XPathPredicate(conditionFragment,attributes.getValue(x));
          predicateFragment.setPredicate(condition);
          resultNode=(XPathNode)nonAttributeChildrenMap.get(predicateFragment);
          if (null != resultNode) {
            break;
          }
        }
        if (null == resultNode) {
          resultNode=xPathNode.getAnyNode();
        }
      }
    }
    return resultNode;
  }
  return null;
}