Program: 65901
Project: 65901
Buggy source:
/** 
 * Creates a new Element and appends a value to an element.
 * @param parent Element which will own the newly created element
 * @param elementName tag name for the new element
 * @param value Node to add
 */
private Node createElement(Node parent,XPathFragment fragment,NamespaceResolver namespaceResolver,Node value){
  String elementName=fragment.getXPath();
  Document document=parent.getOwnerDocument();
  if ((document == null) && (parent.getNodeType() == Node.DOCUMENT_NODE)) {
    document=(Document)parent;
  }
  String nodeUri=value.getNamespaceURI();
  String nodeName=value.getLocalName();
  String fragUri=fragment.getNamespaceURI();
  String fragName=fragment.getLocalName();
  if ((nodeName != null) && nodeName.equals(fragName) && (((nodeUri != null) && nodeUri.equals(fragUri)) || ((nodeUri == null) && (fragUri == null)))) {
    if (document != value.getOwnerDocument()) {
      return document.importNode(value,true);
    }
    return value;
  }
 else {
    String namespace=resolveNamespacePrefix(fragment,namespaceResolver);
    Element clone=document.createElementNS(namespace,elementName);
    NamedNodeMap attributes=value.getAttributes();
    int attributesLength=attributes.getLength();
    for (int index=0; index < attributesLength; index++) {
      Node attribute=document.importNode(attributes.item(index),true);
      clone.setAttributeNode((Attr)attribute);
    }
    NodeList elements=value.getChildNodes();
    int elementsLength=elements.getLength();
    for (int index=0; index < elementsLength; index++) {
      Node attribute=document.importNode(elements.item(index),true);
      clone.appendChild(attribute);
    }
    return clone;
  }
}

Fixed version (ground truth):
/** 
 * Creates a new Element and appends a value to an element.
 * @param parent Element which will own the newly created element
 * @param elementName tag name for the new element
 * @param value Node to add
 */
private Node createElement(Node parent,XPathFragment fragment,NamespaceResolver namespaceResolver,Node value){
  String elementName=fragment.getXPath();
  Document document=parent.getOwnerDocument();
  if ((document == null) && (parent.getNodeType() == Node.DOCUMENT_NODE)) {
    document=(Document)parent;
  }
  String nodeUri=value.getNamespaceURI();
  String nodeName=value.getLocalName();
  String fragUri=fragment.getNamespaceURI();
  String fragName=fragment.getLocalName();
  if ((nodeName != null) && nodeName.equals(fragName) && (((nodeUri != null) && nodeUri.equals(fragUri)) || ((nodeUri == null) && (fragUri == null)))) {
    if (document != value.getOwnerDocument()) {
      return document.importNode(value,true);
    }
    return value;
  }
 else {
    String namespace=resolveNamespacePrefix(fragment,namespaceResolver);
    Element clone=document.createElementNS(namespace,fragName);
    NamedNodeMap attributes=value.getAttributes();
    int attributesLength=attributes.getLength();
    for (int index=0; index < attributesLength; index++) {
      Node attribute=document.importNode(attributes.item(index),true);
      clone.setAttributeNode((Attr)attribute);
    }
    NodeList elements=value.getChildNodes();
    int elementsLength=elements.getLength();
    for (int index=0; index < elementsLength; index++) {
      Node attribute=document.importNode(elements.item(index),true);
      clone.appendChild(attribute);
    }
    return clone;
  }
}