Program: 63522
Project: 63522
Buggy source:
public XPathNode addChild(XPathFragment anXPathFragment,NodeValue aNodeValue,NamespaceResolver namespaceResolver){
  if (null != anXPathFragment && anXPathFragment.nameIsText()) {
    if (aNodeValue.isOwningNode(anXPathFragment)) {
      XPathNode textXPathNode=this.getTextNode();
      if (textXPathNode == null) {
        textXPathNode=new XPathNode();
      }
      textXPathNode.setParent(this);
      textXPathNode.setXPathFragment(anXPathFragment);
      if (aNodeValue.isMarshalNodeValue()) {
        textXPathNode.setMarshalNodeValue(aNodeValue);
      }
      if (aNodeValue.isUnmarshalNodeValue()) {
        textXPathNode.setUnmarshalNodeValue(aNodeValue);
      }
      this.setTextNode(textXPathNode);
      if (null != nonAttributeChildren && !nonAttributeChildren.contains(textXPathNode)) {
        nonAttributeChildren.add(textXPathNode);
      }
      if (aNodeValue instanceof XMLCompositeObjectMappingNodeValue) {
        if (null == selfChildren) {
          selfChildren=new ArrayList<XPathNode>();
        }
        selfChildren.add(textXPathNode);
      }
      return textXPathNode;
    }
  }
  if (anXPathFragment != null && namespaceResolver != null && anXPathFragment.getNamespaceURI() == null && !anXPathFragment.nameIsText()) {
    if (!anXPathFragment.isAttribute()) {
      anXPathFragment.setNamespaceURI(namespaceResolver.resolveNamespacePrefix(anXPathFragment.getPrefix()));
    }
 else     if (anXPathFragment.hasNamespace()) {
      anXPathFragment.setNamespaceURI(namespaceResolver.resolveNamespacePrefix(anXPathFragment.getPrefix()));
    }
  }
  XPathNode xPathNode=new XPathNode();
  xPathNode.setXPathFragment(anXPathFragment);
  List children;
  Map childrenMap;
  if ((anXPathFragment != null) && anXPathFragment.isAttribute()) {
    if (null == attributeChildren) {
      attributeChildren=new ArrayList();
    }
    if (null == attributeChildrenMap) {
      attributeChildrenMap=new HashMap();
    }
    children=attributeChildren;
    childrenMap=attributeChildrenMap;
  }
 else {
    if (null == nonAttributeChildren) {
      nonAttributeChildren=new ArrayList();
      if (null != textNode) {
        nonAttributeChildren.add(textNode);
      }
    }
    if (null == nonAttributeChildrenMap) {
      nonAttributeChildrenMap=new HashMap();
    }
    if (anXPathFragment != null && Constants.SCHEMA_TYPE_ATTRIBUTE.equals(anXPathFragment.getLocalName())) {
      hasTypeChild=true;
    }
    children=nonAttributeChildren;
    childrenMap=nonAttributeChildrenMap;
  }
  if (null == anXPathFragment) {
    if (aNodeValue.isMarshalNodeValue()) {
      xPathNode.setMarshalNodeValue(aNodeValue);
    }
    if (aNodeValue.isUnmarshalNodeValue() && xPathNode.getUnmarshalNodeValue() == null) {
      xPathNode.setUnmarshalNodeValue(aNodeValue);
    }
    xPathNode.setParent(this);
    if (aNodeValue instanceof XMLAnyAttributeMappingNodeValue || (aNodeValue instanceof XMLVariableXPathObjectMappingNodeValue && ((XMLVariableXPathObjectMappingNodeValue)aNodeValue).getMapping().isAttribute()) || (aNodeValue instanceof XMLVariableXPathCollectionMappingNodeValue && ((XMLVariableXPathCollectionMappingNodeValue)aNodeValue).getMapping().isAttribute())) {
      setAnyAttributeNodeValue((MappingNodeValue)aNodeValue);
      anyAttributeNode=xPathNode;
    }
 else {
      if (!children.contains(xPathNode)) {
        children.add(xPathNode);
      }
      setAnyNode(xPathNode);
    }
    return xPathNode;
  }
  this.hasPredicateChildren=hasPredicateChildren || anXPathFragment.getPredicate() != null;
  if (this.getNonAttributeChildren() != null && this.hasPredicateChildren) {
    for (    XPathNode nextChild : this.getNonAttributeChildren()) {
      XPathFragment nextFrag=nextChild.getXPathFragment();
      if (nextFrag != null && nextFrag.equals(anXPathFragment,true)) {
        if (nextFrag.getPredicate() == null && anXPathFragment.getPredicate() != null) {
          nextChild.setHasPredicateSiblings(true);
        }
 else         if (anXPathFragment.getPredicate() == null && nextFrag.getPredicate() != null) {
          xPathNode.setHasPredicateSiblings(true);
        }
      }
    }
  }
  boolean isSelfFragment=XPathFragment.SELF_FRAGMENT.equals(anXPathFragment);
  if (isSelfFragment) {
    children.add(xPathNode);
    if (null == selfChildren) {
      selfChildren=new ArrayList<XPathNode>();
    }
    selfChildren.add(xPathNode);
  }
 else {
    int index=children.indexOf(xPathNode);
    if (index >= 0) {
      xPathNode=(XPathNode)children.get(index);
    }
 else {
      xPathNode.setParent(this);
      if (!children.contains(xPathNode)) {
        children.add(xPathNode);
      }
      childrenMap.put(anXPathFragment,xPathNode);
    }
  }
  if (aNodeValue.isOwningNode(anXPathFragment)) {
    if (aNodeValue.isMarshalNodeValue()) {
      xPathNode.setMarshalNodeValue(aNodeValue);
    }
    if (aNodeValue.isUnmarshalNodeValue() && xPathNode.getUnmarshalNodeValue() == null) {
      xPathNode.setUnmarshalNodeValue(aNodeValue);
    }
  }
 else {
    XPathFragment nextFragment=anXPathFragment.getNextFragment();
    xPathNode.addChild(nextFragment,aNodeValue,namespaceResolver);
  }
  return xPathNode;
}

Fixed version (ground truth):
public XPathNode addChild(XPathFragment anXPathFragment,NodeValue aNodeValue,NamespaceResolver namespaceResolver){
  if (null != anXPathFragment && anXPathFragment.nameIsText()) {
    if (aNodeValue.isOwningNode(anXPathFragment)) {
      XPathNode textXPathNode=this.getTextNode();
      if (textXPathNode == null) {
        textXPathNode=new XPathNode();
      }
      textXPathNode.setParent(this);
      textXPathNode.setXPathFragment(anXPathFragment);
      if (aNodeValue.isMarshalNodeValue()) {
        textXPathNode.setMarshalNodeValue(aNodeValue);
      }
      if (aNodeValue.isUnmarshalNodeValue()) {
        textXPathNode.setUnmarshalNodeValue(aNodeValue);
      }
      this.setTextNode(textXPathNode);
      if (null != nonAttributeChildren && !nonAttributeChildren.contains(textXPathNode)) {
        nonAttributeChildren.add(textXPathNode);
      }
      if (aNodeValue instanceof XMLCompositeObjectMappingNodeValue) {
        if (null == selfChildren) {
          selfChildren=new ArrayList<XPathNode>();
        }
        selfChildren.add(textXPathNode);
      }
      return textXPathNode;
    }
  }
  if (anXPathFragment != null && namespaceResolver != null && anXPathFragment.getNamespaceURI() == null && !anXPathFragment.nameIsText()) {
    if (!anXPathFragment.isAttribute()) {
      anXPathFragment.setNamespaceURI(namespaceResolver.resolveNamespacePrefix(anXPathFragment.getPrefix()));
    }
 else     if (anXPathFragment.hasNamespace()) {
      anXPathFragment.setNamespaceURI(namespaceResolver.resolveNamespacePrefix(anXPathFragment.getPrefix()));
    }
  }
  XPathNode xPathNode=new XPathNode();
  xPathNode.setXPathFragment(anXPathFragment);
  List children;
  Map childrenMap;
  if ((anXPathFragment != null) && anXPathFragment.isAttribute()) {
    if (null == attributeChildren) {
      attributeChildren=new ArrayList();
    }
    if (null == attributeChildrenMap) {
      attributeChildrenMap=new HashMap();
    }
    children=attributeChildren;
    childrenMap=attributeChildrenMap;
  }
 else {
    if (null == nonAttributeChildren) {
      nonAttributeChildren=new ArrayList();
      if (null != textNode) {
        nonAttributeChildren.add(textNode);
      }
    }
    if (null == nonAttributeChildrenMap) {
      nonAttributeChildrenMap=new LinkedHashMap();
    }
    if (anXPathFragment != null && Constants.SCHEMA_TYPE_ATTRIBUTE.equals(anXPathFragment.getLocalName())) {
      hasTypeChild=true;
    }
    children=nonAttributeChildren;
    childrenMap=nonAttributeChildrenMap;
  }
  if (null == anXPathFragment) {
    if (aNodeValue.isMarshalNodeValue()) {
      xPathNode.setMarshalNodeValue(aNodeValue);
    }
    if (aNodeValue.isUnmarshalNodeValue() && xPathNode.getUnmarshalNodeValue() == null) {
      xPathNode.setUnmarshalNodeValue(aNodeValue);
    }
    xPathNode.setParent(this);
    if (aNodeValue instanceof XMLAnyAttributeMappingNodeValue || (aNodeValue instanceof XMLVariableXPathObjectMappingNodeValue && ((XMLVariableXPathObjectMappingNodeValue)aNodeValue).getMapping().isAttribute()) || (aNodeValue instanceof XMLVariableXPathCollectionMappingNodeValue && ((XMLVariableXPathCollectionMappingNodeValue)aNodeValue).getMapping().isAttribute())) {
      setAnyAttributeNodeValue((MappingNodeValue)aNodeValue);
      anyAttributeNode=xPathNode;
    }
 else {
      if (!children.contains(xPathNode)) {
        children.add(xPathNode);
      }
      setAnyNode(xPathNode);
    }
    return xPathNode;
  }
  this.hasPredicateChildren=hasPredicateChildren || anXPathFragment.getPredicate() != null;
  if (this.getNonAttributeChildren() != null && this.hasPredicateChildren) {
    for (    XPathNode nextChild : this.getNonAttributeChildren()) {
      XPathFragment nextFrag=nextChild.getXPathFragment();
      if (nextFrag != null && nextFrag.equals(anXPathFragment,true)) {
        if (nextFrag.getPredicate() == null && anXPathFragment.getPredicate() != null) {
          nextChild.setHasPredicateSiblings(true);
        }
 else         if (anXPathFragment.getPredicate() == null && nextFrag.getPredicate() != null) {
          xPathNode.setHasPredicateSiblings(true);
        }
      }
    }
  }
  boolean isSelfFragment=XPathFragment.SELF_FRAGMENT.equals(anXPathFragment);
  if (isSelfFragment) {
    children.add(xPathNode);
    if (null == selfChildren) {
      selfChildren=new ArrayList<XPathNode>();
    }
    selfChildren.add(xPathNode);
  }
 else {
    int index=children.indexOf(xPathNode);
    if (index >= 0) {
      xPathNode=(XPathNode)children.get(index);
    }
 else {
      xPathNode.setParent(this);
      if (!children.contains(xPathNode)) {
        children.add(xPathNode);
      }
      childrenMap.put(anXPathFragment,xPathNode);
    }
  }
  if (aNodeValue.isOwningNode(anXPathFragment)) {
    if (aNodeValue.isMarshalNodeValue()) {
      xPathNode.setMarshalNodeValue(aNodeValue);
    }
    if (aNodeValue.isUnmarshalNodeValue() && xPathNode.getUnmarshalNodeValue() == null) {
      xPathNode.setUnmarshalNodeValue(aNodeValue);
    }
  }
 else {
    XPathFragment nextFragment=anXPathFragment.getNextFragment();
    xPathNode.addChild(nextFragment,aNodeValue,namespaceResolver);
  }
  return xPathNode;
}