Program: 68304
Project: 68304
Buggy source:
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;
  AbstractSession session=xmlContext.getSession(descriptor);
  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(session),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,session);
    }
    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,session);
  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;
  AbstractSession session=xmlContext.getSession(descriptor);
  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 && !(xmlRootUri.equals(resolver.getDefaultNamespaceURI()))) {
          xmlRootPrefix=resolver.generatePrefix();
          resolver.put(xmlRootPrefix,xmlRootUri);
          shouldCallSetAttributeNS=true;
        }
        if (xmlRootPrefix != null) {
          recordName=xmlRootPrefix + "String_Node_Str" + recordName;
        }
      }
      xmlRow=(XMLRecord)((XMLObjectBuilder)descriptor.getObjectBuilder()).createRecordFor(((XMLRoot)object).getObject(),xmlContext.getDocumentPreservationPolicy(session),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,session);
    }
    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,session);
  return document;
}