Program: 65570
Project: 65570
Buggy source:
public void writeSingleValue(Object element,Object parent,XMLRecord row,AbstractSession session){
  XMLField xmlRootField=null;
  Object originalObject=element;
  DOMRecord record=(DOMRecord)row;
  Node root=record.getDOM();
  org.w3c.dom.Document doc=row.getDocument();
  boolean wasXMLRoot=false;
  if (usesXMLRoot() && (element instanceof XMLRoot)) {
    wasXMLRoot=true;
    xmlRootField=new XMLField();
    XPathFragment frag=new XPathFragment();
    if ((((XMLRoot)element)).getRootFragment().getNamespaceURI() != null) {
      frag.setNamespaceURI(((XMLRoot)element).getNamespaceURI());
    }
 else {
      frag.setXPath(((XMLRoot)element).getLocalName());
    }
    xmlRootField.setXPathFragment(frag);
    xmlRootField.setNamespaceResolver(row.getNamespaceResolver());
    element=((XMLRoot)element).getObject();
  }
  if (element instanceof String) {
    writeSimpleValue(xmlRootField,element,originalObject,record,doc,root,wasXMLRoot,session);
  }
 else   if (element instanceof org.w3c.dom.Node) {
    Node importedCopy=doc.importNode((Node)element,true);
    root.appendChild(importedCopy);
  }
 else {
    XMLDescriptor referenceDescriptor=(XMLDescriptor)session.getDescriptor(element.getClass());
    if (referenceDescriptor == null) {
      writeSimpleValue(xmlRootField,element,originalObject,record,doc,root,wasXMLRoot,session);
      return;
    }
    if (wasXMLRoot) {
      if (((XMLRoot)originalObject).getRootFragment().getNamespaceURI() != null) {
        String prefix=referenceDescriptor.getNonNullNamespaceResolver().resolveNamespaceURI(((XMLRoot)originalObject).getNamespaceURI());
        if ((prefix == null) || prefix.length() == 0) {
          prefix=record.getNamespaceResolver().resolveNamespaceURI(((XMLRoot)originalObject).getRootFragment().getNamespaceURI());
        }
        if ((prefix == null) || prefix.length() == 0) {
          xmlRootField.getXPathFragment().setGeneratedPrefix(true);
          prefix=record.getNamespaceResolver().generatePrefix();
        }
        xmlRootField.getXPathFragment().setXPath(prefix + XMLConstants.COLON + ((XMLRoot)originalObject).getLocalName());
      }
    }
    DOMRecord nestedRecord=(DOMRecord)buildCompositeRow(element,session,referenceDescriptor,row,xmlRootField,originalObject,wasXMLRoot);
    if (nestedRecord != null) {
      root.appendChild(nestedRecord.getDOM());
    }
  }
}

Fixed version (ground truth):
public void writeSingleValue(Object element,Object parent,XMLRecord row,AbstractSession session){
  XMLField xmlRootField=null;
  Object originalObject=element;
  DOMRecord record=(DOMRecord)row;
  Node root=record.getDOM();
  org.w3c.dom.Document doc=row.getDocument();
  boolean wasXMLRoot=false;
  if (usesXMLRoot() && (element instanceof XMLRoot)) {
    wasXMLRoot=true;
    xmlRootField=new XMLField();
    XPathFragment frag=new XPathFragment();
    if ((((XMLRoot)element)).getNamespaceURI() != null) {
      frag.setNamespaceURI(((XMLRoot)element).getNamespaceURI());
    }
    frag.setLocalName(((XMLRoot)element).getLocalName());
    xmlRootField.setXPathFragment(frag);
    xmlRootField.setNamespaceResolver(row.getNamespaceResolver());
    element=((XMLRoot)element).getObject();
  }
  if (element instanceof String) {
    writeSimpleValue(xmlRootField,element,originalObject,record,doc,root,wasXMLRoot,session);
  }
 else   if (element instanceof org.w3c.dom.Node) {
    Node importedCopy=doc.importNode((Node)element,true);
    root.appendChild(importedCopy);
  }
 else {
    XMLDescriptor referenceDescriptor=(XMLDescriptor)session.getDescriptor(element.getClass());
    if (referenceDescriptor == null) {
      writeSimpleValue(xmlRootField,element,originalObject,record,doc,root,wasXMLRoot,session);
      return;
    }
    if (wasXMLRoot) {
      if (((XMLRoot)originalObject).getNamespaceURI() != null) {
        String prefix=referenceDescriptor.getNonNullNamespaceResolver().resolveNamespaceURI(((XMLRoot)originalObject).getNamespaceURI());
        if ((prefix == null) || prefix.length() == 0) {
          prefix=record.getNamespaceResolver().resolveNamespaceURI(((XMLRoot)originalObject).getNamespaceURI());
        }
        if ((prefix == null) || prefix.length() == 0) {
          xmlRootField.getXPathFragment().setGeneratedPrefix(true);
          prefix=record.getNamespaceResolver().generatePrefix();
        }
        xmlRootField.getXPathFragment().setXPath(prefix + XMLConstants.COLON + ((XMLRoot)originalObject).getLocalName());
      }
    }
    DOMRecord nestedRecord=(DOMRecord)buildCompositeRow(element,session,referenceDescriptor,row,xmlRootField,originalObject,wasXMLRoot);
    if (nestedRecord != null) {
      root.appendChild(nestedRecord.getDOM());
    }
  }
}