Program: 68728
Project: 68728
Buggy source:
/** 
 * INTERNAL: Convert the given object to an XML Document
 */
public Document objectToXML(Object object,XMLDescriptor descriptor,XMLRecord xmlRow,boolean isXMLRoot){
  Document document=null;
  NamespaceResolver resolver=new NamespaceResolver();
  this.copyNamespaces(descriptor.getNamespaceResolver(),resolver);
  boolean shouldCallSetAttributeNS=false;
  boolean isRootDocumentFragment=false;
  if (xmlRow != null) {
    isRootDocumentFragment=(xmlRow.getDOM().getNodeType() == Node.DOCUMENT_FRAGMENT_NODE);
  }
  if (isXMLRoot) {
    String xmlRootUri=((XMLRoot)object).getNamespaceURI();
    String xmlRootPrefix=null;
    if (xmlRow == null) {
      String recordName=((XMLRoot)object).getLocalName();
      if (xmlRootUri != null) {
        xmlRootPrefix=resolver.resolveNamespaceURI(xmlRootUri);
        if (xmlRootPrefix == null) {
          xmlRootPrefix=resolver.generatePrefix();
          resolver.put(xmlRootPrefix,xmlRootUri);
        }
        recordName=xmlRootPrefix + "String_Node_Str" + recordName;
        shouldCallSetAttributeNS=true;
      }
      xmlRow=(XMLRecord)((XMLObjectBuilder)descriptor.getObjectBuilder()).createRecordFor(((XMLRoot)object).getObject(),xmlContext.getDocumentPreservationPolicy(xmlContext.getSession(descriptor)),recordName,xmlRootUri);
      xmlRow.setMarshaller(this);
      if (!isRootDocumentFragment) {
        if (shouldCallSetAttributeNS) {
          if (xmlRootPrefix != null) {
            ((Element)xmlRow.getDOM()).setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + "String_Node_Str" + xmlRootPrefix,xmlRootUri);
          }
          shouldCallSetAttributeNS=false;
        }
      }
    }
    copyNamespaces(resolver,xmlRow.getNamespaceResolver());
    document=xmlRow.getDocument();
    Element docElement=document.getDocumentElement();
    xmlRow.getNamespaceResolver().put(XMLConstants.SCHEMA_INSTANCE_PREFIX,XMLConstants.SCHEMA_INSTANCE_URL);
    boolean writeTypeAttribute=shouldWriteTypeAttribute(object,descriptor,isXMLRoot);
    if (writeTypeAttribute && (descriptor.getSchemaReference() != null) && (descriptor.getSchemaReference().getSchemaContext() != null)) {
      ((Element)xmlRow.getDOM()).setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + "String_Node_Str" + XMLConstants.SCHEMA_INSTANCE_PREFIX,XMLConstants.SCHEMA_INSTANCE_URL);
      String typeValue=descriptor.getSchemaReference().getSchemaContext();
      typeValue=typeValue.substring(1);
      XMLField xsiTypefield=new XMLField("String_Node_Str");
      xsiTypefield.setNamespaceResolver(xmlRow.getNamespaceResolver());
      XPathEngine.getInstance().create(xsiTypefield,docElement,typeValue);
    }
    object=((XMLRoot)object).getObject();
  }
  XMLObjectBuilder bldr=(XMLObjectBuilder)descriptor.getObjectBuilder();
  xmlRow=(XMLRecord)bldr.buildRow(xmlRow,object,xmlContext.getSession(object),isXMLRoot);
  xmlRow.setMarshaller(this);
  if (shouldCallSetAttributeNS && !isRootDocumentFragment) {
    ((Element)xmlRow.getDOM()).setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + "String_Node_Str" + XMLConstants.SCHEMA_INSTANCE_PREFIX,XMLConstants.SCHEMA_INSTANCE_URL);
  }
  document=xmlRow.getDocument();
  addSchemaLocations(document);
  return document;
}

Fixed version (ground truth):
private Document objectToXML(Object object,Node rootNode,XMLDescriptor descriptor,XMLRecord xmlRow,boolean isXMLRoot){
  Document document=null;
  NamespaceResolver resolver=new NamespaceResolver();
  resolver.setDOM(rootNode);
  this.copyNamespaces(descriptor.getNamespaceResolver(),resolver);
  boolean shouldCallSetAttributeNS=false;
  boolean isRootDocumentFragment=false;
  if (xmlRow != null) {
    isRootDocumentFragment=(xmlRow.getDOM().getNodeType() == Node.DOCUMENT_FRAGMENT_NODE);
  }
  if (isXMLRoot) {
    String xmlRootUri=((XMLRoot)object).getNamespaceURI();
    String xmlRootPrefix=null;
    if (xmlRow == null) {
      String recordName=((XMLRoot)object).getLocalName();
      if (xmlRootUri != null) {
        xmlRootPrefix=resolver.resolveNamespaceURI(xmlRootUri);
        if (xmlRootPrefix == null) {
          xmlRootPrefix=resolver.generatePrefix();
          resolver.put(xmlRootPrefix,xmlRootUri);
          shouldCallSetAttributeNS=true;
        }
        recordName=xmlRootPrefix + "String_Node_Str" + recordName;
      }
      xmlRow=(XMLRecord)((XMLObjectBuilder)descriptor.getObjectBuilder()).createRecordFor(((XMLRoot)object).getObject(),xmlContext.getDocumentPreservationPolicy(xmlContext.getSession(descriptor)),recordName,xmlRootUri);
      xmlRow.setMarshaller(this);
      if (!isRootDocumentFragment) {
        if (shouldCallSetAttributeNS) {
          if (xmlRootPrefix != null) {
            ((Element)xmlRow.getDOM()).setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + "String_Node_Str" + xmlRootPrefix,xmlRootUri);
          }
          shouldCallSetAttributeNS=false;
        }
      }
    }
    copyNamespaces(resolver,xmlRow.getNamespaceResolver());
    document=xmlRow.getDocument();
    Element docElement=document.getDocumentElement();
    xmlRow.getNamespaceResolver().put(XMLConstants.SCHEMA_INSTANCE_PREFIX,XMLConstants.SCHEMA_INSTANCE_URL);
    boolean writeTypeAttribute=shouldWriteTypeAttribute(object,descriptor,isXMLRoot);
    if (writeTypeAttribute && (descriptor.getSchemaReference() != null) && (descriptor.getSchemaReference().getSchemaContext() != null)) {
      ((Element)xmlRow.getDOM()).setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + "String_Node_Str" + XMLConstants.SCHEMA_INSTANCE_PREFIX,XMLConstants.SCHEMA_INSTANCE_URL);
      String typeValue=descriptor.getSchemaReference().getSchemaContext();
      typeValue=typeValue.substring(1);
      XMLField xsiTypefield=new XMLField("String_Node_Str");
      xsiTypefield.setNamespaceResolver(xmlRow.getNamespaceResolver());
      XPathEngine.getInstance().create(xsiTypefield,docElement,typeValue);
    }
    object=((XMLRoot)object).getObject();
  }
  XMLObjectBuilder bldr=(XMLObjectBuilder)descriptor.getObjectBuilder();
  xmlRow=(XMLRecord)bldr.buildRow(xmlRow,object,(AbstractSession)xmlContext.getSession(object),isXMLRoot);
  xmlRow.setMarshaller(this);
  if (shouldCallSetAttributeNS && !isRootDocumentFragment) {
    ((Element)xmlRow.getDOM()).setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + "String_Node_Str" + XMLConstants.SCHEMA_INSTANCE_PREFIX,XMLConstants.SCHEMA_INSTANCE_URL);
  }
  document=xmlRow.getDocument();
  addSchemaLocations(document);
  return document;
}