Program: 67447
Project: 67447
Buggy source:
public Document objectToXML(Object object,Node rootNode,XMLDescriptor descriptor,XMLRecord xmlRow,boolean isXMLRoot,DocumentPreservationPolicy docPresPolicy){
  if (null != rootNode) {
    int rootNodeType=rootNode.getNodeType();
    if (rootNodeType != Node.DOCUMENT_NODE && rootNodeType != Node.ELEMENT_NODE && rootNodeType != Node.DOCUMENT_FRAGMENT_NODE) {
      throw XMLMarshalException.marshalException(null);
    }
  }
  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(),docPresPolicy,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):
public Document objectToXML(Object object,Node rootNode,XMLDescriptor descriptor,XMLRecord xmlRow,boolean isXMLRoot,DocumentPreservationPolicy docPresPolicy){
  if (null != rootNode) {
    int rootNodeType=rootNode.getNodeType();
    if (rootNodeType != Node.DOCUMENT_NODE && rootNodeType != Node.ELEMENT_NODE && rootNodeType != Node.DOCUMENT_FRAGMENT_NODE) {
      throw XMLMarshalException.marshalException(null);
    }
  }
  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(),docPresPolicy,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();
  }
 else {
    xmlRow=(XMLRecord)((XMLObjectBuilder)descriptor.getObjectBuilder()).createRecordFor(object,docPresPolicy);
  }
  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;
}