Program: 66121
Project: 66121
Buggy source:
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object targetObject,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  Object fieldValue=xmlObjectReferenceMapping.buildFieldValue(targetObject,xmlField,session);
  if (fieldValue == null) {
    if (null != targetObject) {
      XMLField fkField=(XMLField)xmlObjectReferenceMapping.getSourceToTargetKeyFieldAssociations().get(xmlField);
      if (null == fkField) {
        XMLDescriptor targetDescriptor=(XMLDescriptor)session.getDescriptor(targetObject);
        fieldValue=marshalRecord.getMarshaller().getXMLContext().getValueByXPath(targetObject,targetDescriptor.getPrimaryKeyFields().get(0).getName(),targetDescriptor.getNamespaceResolver(),Object.class);
      }
 else {
        fieldValue=marshalRecord.getMarshaller().getXMLContext().getValueByXPath(targetObject,fkField.getXPath(),fkField.getNamespaceResolver(),Object.class);
      }
    }
    if (null == fieldValue) {
      return false;
    }
  }
  QName schemaType=getSchemaType(xmlField,fieldValue,session);
  String stringValue=getValueToWrite(schemaType,fieldValue,(XMLConversionManager)session.getDatasourcePlatform().getConversionManager(),namespaceResolver);
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  if (xPathFragment.isAttribute()) {
    marshalRecord.attribute(xPathFragment,namespaceResolver,stringValue);
    marshalRecord.closeStartGroupingElements(groupingFragment);
  }
 else {
    marshalRecord.closeStartGroupingElements(groupingFragment);
    marshalRecord.characters(stringValue);
  }
  return true;
}

Fixed version (ground truth):
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object targetObject,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  Object fieldValue=xmlObjectReferenceMapping.buildFieldValue(targetObject,xmlField,session);
  if (fieldValue == null) {
    if (null != targetObject) {
      XMLField fkField=(XMLField)xmlObjectReferenceMapping.getSourceToTargetKeyFieldAssociations().get(xmlField);
      if (null == fkField) {
        XMLDescriptor targetDescriptor=(XMLDescriptor)session.getDescriptor(targetObject);
        fieldValue=marshalRecord.getMarshaller().getXMLContext().getValueByXPath(targetObject,targetDescriptor.getPrimaryKeyFields().get(0).getName(),targetDescriptor.getNamespaceResolver(),Object.class);
      }
 else {
        fieldValue=marshalRecord.getMarshaller().getXMLContext().getValueByXPath(targetObject,fkField.getXPath(),fkField.getNamespaceResolver(),Object.class);
      }
    }
    if (null == fieldValue) {
      return false;
    }
  }
  QName schemaType=getSchemaType(xmlField,fieldValue,session);
  String stringValue=getValueToWrite(schemaType,fieldValue,(XMLConversionManager)session.getDatasourcePlatform().getConversionManager(),marshalRecord);
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  if (xPathFragment.isAttribute()) {
    marshalRecord.attribute(xPathFragment,namespaceResolver,stringValue);
    marshalRecord.closeStartGroupingElements(groupingFragment);
  }
 else {
    marshalRecord.closeStartGroupingElements(groupingFragment);
    marshalRecord.characters(stringValue);
  }
  return true;
}