Program: 68604
Project: 68604
Buggy source:
public AbstractRecord buildIntoNestedRow(AbstractRecord row,Object object,AbstractSession session,boolean shouldWriteXsiType){
  XMLRecord record=(XMLRecord)row;
  XMLMarshaller marshaller=record.getMarshaller();
  if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
    marshaller.getMarshalListener().beforeMarshal(object);
  }
  List extraNamespaces=null;
  if (isXmlDescriptor()) {
    XMLDescriptor xmlDescriptor=(XMLDescriptor)getDescriptor();
    extraNamespaces=addExtraNamespacesToNamespaceResolver(xmlDescriptor,record,session);
    writeExtraNamespaces(extraNamespaces,record);
  }
  writeOutMappings(record,object,session);
  if (isXmlDescriptor()) {
    XMLDescriptor xmlDescriptor=(XMLDescriptor)getDescriptor();
    XMLSchemaReference xmlRef=xmlDescriptor.getSchemaReference();
    if (shouldWriteXsiType) {
      writeXsiTypeAttribute(xmlDescriptor,(DOMRecord)record,xmlRef.getSchemaContext().substring(1));
    }
    if (getDescriptor().hasInheritance()) {
      if ((record.getLeafElementType() != null) && ((xmlRef.getType() == 1) && xmlRef.isGlobalDefinition())) {
        QName ctxQName=xmlRef.getSchemaContextAsQName(xmlDescriptor.getNamespaceResolver());
        if (ctxQName.equals(record.getLeafElementType())) {
        }
 else {
          XMLField xmlField=(XMLField)xmlDescriptor.getInheritancePolicy().getClassIndicatorField();
          if (xmlField.getLastXPathFragment().isAttribute()) {
            writeXsiTypeAttribute(xmlDescriptor,(DOMRecord)record,xmlRef.getSchemaContext().substring(1));
          }
 else {
            writeXsiTypeAttribute(xmlDescriptor,(DOMRecord)record,xmlRef.getSchemaContext().substring(1));
          }
        }
      }
 else {
        if (!xmlDescriptor.getInheritancePolicy().hasClassExtractor()) {
          XMLField xmlField=(XMLField)xmlDescriptor.getInheritancePolicy().getClassIndicatorField();
          if (xmlField.getLastXPathFragment().isAttribute()) {
            getDescriptor().getInheritancePolicy().addClassIndicatorFieldToRow(row);
          }
 else {
            getDescriptor().getInheritancePolicy().addClassIndicatorFieldToRow(row);
          }
        }
      }
    }
    removeExtraNamespacesFromNamespaceResolver(record,extraNamespaces,session);
  }
  if (!getDescriptor().isAggregateDescriptor()) {
    addPrimaryKeyForNonDefaultTable(row);
  }
  if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
    marshaller.getMarshalListener().afterMarshal(object);
  }
  return row;
}

Fixed version (ground truth):
public AbstractRecord buildIntoNestedRow(AbstractRecord row,Object object,AbstractSession session,boolean shouldWriteXsiType){
  XMLRecord record=(XMLRecord)row;
  record.setSession(session);
  XMLMarshaller marshaller=record.getMarshaller();
  if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
    marshaller.getMarshalListener().beforeMarshal(object);
  }
  List extraNamespaces=null;
  if (isXmlDescriptor()) {
    XMLDescriptor xmlDescriptor=(XMLDescriptor)getDescriptor();
    extraNamespaces=addExtraNamespacesToNamespaceResolver(xmlDescriptor,record,session);
    writeExtraNamespaces(extraNamespaces,record);
  }
  writeOutMappings(record,object,session);
  if (isXmlDescriptor()) {
    XMLDescriptor xmlDescriptor=(XMLDescriptor)getDescriptor();
    XMLSchemaReference xmlRef=xmlDescriptor.getSchemaReference();
    if (shouldWriteXsiType) {
      writeXsiTypeAttribute(xmlDescriptor,(DOMRecord)record,xmlRef.getSchemaContext().substring(1));
    }
    if (getDescriptor().hasInheritance()) {
      if ((record.getLeafElementType() != null) && ((xmlRef.getType() == 1) && xmlRef.isGlobalDefinition())) {
        QName ctxQName=xmlRef.getSchemaContextAsQName(xmlDescriptor.getNamespaceResolver());
        if (ctxQName.equals(record.getLeafElementType())) {
        }
 else {
          XMLField xmlField=(XMLField)xmlDescriptor.getInheritancePolicy().getClassIndicatorField();
          if (xmlField.getLastXPathFragment().isAttribute()) {
            writeXsiTypeAttribute(xmlDescriptor,(DOMRecord)record,xmlRef.getSchemaContext().substring(1));
          }
 else {
            writeXsiTypeAttribute(xmlDescriptor,(DOMRecord)record,xmlRef.getSchemaContext().substring(1));
          }
        }
      }
 else {
        if (!xmlDescriptor.getInheritancePolicy().hasClassExtractor()) {
          XMLField xmlField=(XMLField)xmlDescriptor.getInheritancePolicy().getClassIndicatorField();
          if (xmlField.getLastXPathFragment().isAttribute()) {
            getDescriptor().getInheritancePolicy().addClassIndicatorFieldToRow(row);
          }
 else {
            getDescriptor().getInheritancePolicy().addClassIndicatorFieldToRow(row);
          }
        }
      }
    }
    removeExtraNamespacesFromNamespaceResolver(record,extraNamespaces,session);
  }
  if (!getDescriptor().isAggregateDescriptor()) {
    addPrimaryKeyForNonDefaultTable(row);
  }
  if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
    marshaller.getMarshalListener().afterMarshal(object);
  }
  return row;
}