Program: 65269
Project: 65269
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();
    }
    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) {
      setAnyAttributeNodeValue((XMLAnyAttributeMappingNodeValue)aNodeValue);
      anyAttributeNode=xPathNode;
    }
 else {
      if (!children.contains(xPathNode)) {
        children.add(xPathNode);
      }
      setAnyNode(xPathNode);
    }
    return xPathNode;
  }
  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 HashMap();
    }
    if (anXPathFragment != null && XMLConstants.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) {
      setAnyAttributeNodeValue((XMLAnyAttributeMappingNodeValue)aNodeValue);
      anyAttributeNode=xPathNode;
    }
 else {
      if (!children.contains(xPathNode)) {
        children.add(xPathNode);
      }
      setAnyNode(xPathNode);
    }
    return xPathNode;
  }
  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;
}