Program: 64679
Project: 64679
Buggy source:
private <T>T getValueByXPath(Object object,ObjectBuilder objectBuilder,StringTokenizer stringTokenizer,NamespaceResolver namespaceResolver,Class<T> returnType){
  if (null == object) {
    return null;
  }
  String xPath="String_Node_Str";
  XMLField xmlField=new XMLField();
  xmlField.setNamespaceResolver(namespaceResolver);
  while (stringTokenizer.hasMoreElements()) {
    String nextToken=stringTokenizer.nextToken();
    xmlField.setXPath(xPath + nextToken);
    xmlField.initialize();
    DatabaseMapping mapping=objectBuilder.getMappingForField(xmlField);
    if (null == mapping) {
      XPathFragment xPathFragment=new XPathFragment(nextToken);
      if (xPathFragment.getIndexValue() > 0) {
        xmlField.setXPath(xPath + nextToken.substring(0,nextToken.indexOf('[')));
        xmlField.initialize();
        mapping=objectBuilder.getMappingForField(xmlField);
        if (null != mapping) {
          if (mapping.isCollectionMapping()) {
            if (mapping.getContainerPolicy().isListPolicy()) {
              Object childObject=((ListContainerPolicy)mapping.getContainerPolicy()).get(xPathFragment.getIndexValue() - 1,mapping.getAttributeValueFromObject(object),null);
              if (stringTokenizer.hasMoreElements()) {
                ObjectBuilder childObjectBuilder=mapping.getReferenceDescriptor().getObjectBuilder();
                return getValueByXPath(childObject,childObjectBuilder,stringTokenizer,namespaceResolver,returnType);
              }
 else {
                return (T)childObject;
              }
            }
          }
        }
      }
    }
 else {
      if (stringTokenizer.hasMoreElements()) {
        Object childObject=mapping.getAttributeValueFromObject(object);
        ObjectBuilder childObjectBuilder=mapping.getReferenceDescriptor().getObjectBuilder();
        return getValueByXPath(childObject,childObjectBuilder,stringTokenizer,namespaceResolver,returnType);
      }
 else {
        return (T)mapping.getAttributeValueFromObject(object);
      }
    }
    xPath=xPath + nextToken + "String_Node_Str";
  }
  return null;
}

Fixed version (ground truth):
private <T>T getValueByXPath(Object object,ObjectBuilder objectBuilder,StringTokenizer stringTokenizer,NamespaceResolver namespaceResolver,Class<T> returnType){
  if (null == object) {
    return null;
  }
  String xPath="String_Node_Str";
  XMLField xmlField=new XMLField();
  xmlField.setNamespaceResolver(namespaceResolver);
  while (stringTokenizer.hasMoreElements()) {
    String nextToken=stringTokenizer.nextToken();
    xmlField.setXPath(xPath + nextToken);
    xmlField.initialize();
    DatabaseMapping mapping=objectBuilder.getMappingForField(xmlField);
    if (null == mapping) {
      XPathFragment xPathFragment=new XPathFragment(nextToken);
      int xmlFieldIndex=xmlField.getXPathFragment().getIndexValue();
      int fragmentIndex=xPathFragment.getIndexValue();
      if (xmlFieldIndex > 0 || fragmentIndex > 0) {
        int index=xmlFieldIndex - 1;
        if (index < 0) {
          index=fragmentIndex - 1;
        }
        String strippedXPath=xmlField.getXPath();
        while (strippedXPath.contains("String_Node_Str")) {
          int open=strippedXPath.lastIndexOf('[');
          int closed=strippedXPath.lastIndexOf(']');
          strippedXPath=strippedXPath.substring(0,open) + strippedXPath.substring(closed + 1);
        }
        xmlField.setXPath(strippedXPath);
        xmlField.initialize();
        mapping=objectBuilder.getMappingForField(xmlField);
        if (null != mapping) {
          if (mapping.isCollectionMapping()) {
            Object childObject=null;
            Object collection=mapping.getAttributeValueFromObject(object);
            if (List.class.isAssignableFrom(collection.getClass())) {
              List list=(List)collection;
              if (index >= list.size()) {
                return null;
              }
              childObject=list.get(index);
            }
            if (stringTokenizer.hasMoreElements()) {
              ObjectBuilder childObjectBuilder=mapping.getReferenceDescriptor().getObjectBuilder();
              return getValueByXPath(childObject,childObjectBuilder,stringTokenizer,namespaceResolver,returnType);
            }
 else {
              return (T)childObject;
            }
          }
        }
      }
    }
 else {
      if (stringTokenizer.hasMoreElements()) {
        Object childObject=mapping.getAttributeValueFromObject(object);
        ObjectBuilder childObjectBuilder=mapping.getReferenceDescriptor().getObjectBuilder();
        return getValueByXPath(childObject,childObjectBuilder,stringTokenizer,namespaceResolver,returnType);
      }
 else {
        return (T)mapping.getAttributeValueFromObject(object);
      }
    }
    xPath=xPath + nextToken + "String_Node_Str";
  }
  return null;
}