Program: 64910
Project: 64910
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);
  }
  Object originalObject=object;
  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 + XMLConstants.COLON + recordName;
        }
      }
      xmlRow=(XMLRecord)((XMLObjectBuilder)descriptor.getObjectBuilder()).createRecordFor(((XMLRoot)object).getObject(),docPresPolicy,recordName,xmlRootUri);
      xmlRow.setMarshaller(this);
      if (getAttachmentMarshaller() != null) {
        xmlRow.setXOPPackage(getAttachmentMarshaller().isXOPPackage());
      }
      if (!isRootDocumentFragment) {
        if (shouldCallSetAttributeNS) {
          if (xmlRootPrefix != null) {
            ((Element)xmlRow.getDOM()).setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + XMLConstants.COLON + xmlRootPrefix,xmlRootUri);
          }
          shouldCallSetAttributeNS=false;
        }
      }
    }
    copyNamespaces(resolver,xmlRow.getNamespaceResolver());
    document=xmlRow.getDocument();
    Element docElement=document.getDocumentElement();
    object=((XMLRoot)object).getObject();
  }
  XMLObjectBuilder bldr=(XMLObjectBuilder)descriptor.getObjectBuilder();
  AbstractSession objectSession=xmlContext.getSession(object);
  xmlRow.setSession(objectSession);
  bldr.addXsiTypeAndClassIndicatorIfRequired(xmlRow,descriptor,null,null,originalObject,object,isXMLRoot,true);
  xmlRow=(XMLRecord)bldr.buildRow(xmlRow,object,objectSession,isXMLRoot);
  xmlRow.setMarshaller(this);
  if (shouldCallSetAttributeNS && !isRootDocumentFragment) {
    ((Element)xmlRow.getDOM()).setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + XMLConstants.COLON + 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);
  }
  Object originalObject=object;
  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 + XMLConstants.COLON + recordName;
        }
      }
      xmlRow=(XMLRecord)((XMLObjectBuilder)descriptor.getObjectBuilder()).createRecordFor(((XMLRoot)object).getObject(),docPresPolicy,recordName,xmlRootUri);
      xmlRow.setMarshaller(this);
      if (this.attachmentMarshaller != null) {
        xmlRow.setXOPPackage(this.attachmentMarshaller.isXOPPackage());
      }
      if (!isRootDocumentFragment) {
        if (shouldCallSetAttributeNS) {
          if (xmlRootPrefix != null) {
            ((Element)xmlRow.getDOM()).setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + XMLConstants.COLON + xmlRootPrefix,xmlRootUri);
          }
          shouldCallSetAttributeNS=false;
        }
      }
    }
    copyNamespaces(resolver,xmlRow.getNamespaceResolver());
    document=xmlRow.getDocument();
    Element docElement=document.getDocumentElement();
    object=((XMLRoot)object).getObject();
  }
  XMLObjectBuilder bldr=(XMLObjectBuilder)descriptor.getObjectBuilder();
  AbstractSession objectSession=xmlContext.getSession(object);
  xmlRow.setSession(objectSession);
  bldr.addXsiTypeAndClassIndicatorIfRequired(xmlRow,descriptor,null,null,originalObject,object,isXMLRoot,true);
  xmlRow=(XMLRecord)bldr.buildRow(xmlRow,object,objectSession,isXMLRoot);
  xmlRow.setMarshaller(this);
  if (shouldCallSetAttributeNS && !isRootDocumentFragment) {
    ((Element)xmlRow.getDOM()).setAttributeNS(XMLConstants.XMLNS_URL,XMLConstants.XMLNS + XMLConstants.COLON + XMLConstants.SCHEMA_INSTANCE_PREFIX,XMLConstants.SCHEMA_INSTANCE_URL);
  }
  document=xmlRow.getDocument();
  addSchemaLocations(document,session);
  return document;
}