Program: 66844
Project: 66844
Buggy source:
/** 
 * Handle the marshal operation for this NodeValue.  Each of the target object's primary key values that are mapped to the collection mapping's fields  (in the XMLCollectionReferenceMapping's source-target key field association list) are retrieved and written out. 
 */
public boolean marshal(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,AbstractSession session,NamespaceResolver namespaceResolver){
  ContainerPolicy cp=xmlCollectionReferenceMapping.getContainerPolicy();
  Object collection=xmlCollectionReferenceMapping.getAttributeAccessor().getAttributeValueFromObject(object);
  if (collection == null) {
    return false;
  }
  Object iterator=cp.iteratorFor(collection);
  if (cp.hasNext(iterator)) {
    XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
    marshalRecord.closeStartGroupingElements(groupingFragment);
  }
 else {
    return false;
  }
  Object objectValue;
  String stringValue=XMLConstants.EMPTY_STRING;
  String newValue;
  QName schemaType;
  if (xmlCollectionReferenceMapping.usesSingleNode()) {
    while (cp.hasNext(iterator)) {
      objectValue=cp.next(iterator,session);
      Object fieldValue=xmlCollectionReferenceMapping.buildFieldValue(objectValue,xmlField,session);
      if (fieldValue == null) {
        return false;
      }
      schemaType=getSchemaType(xmlField,fieldValue,session);
      newValue=getValueToWrite(schemaType,fieldValue,(XMLConversionManager)session.getDatasourcePlatform().getConversionManager(),namespaceResolver);
      if (newValue != null) {
        stringValue+=newValue;
        if (cp.hasNext(iterator)) {
          stringValue+=SPACE;
        }
      }
    }
    marshalSingleValue(xPathFragment,marshalRecord,object,stringValue,session,namespaceResolver,ObjectMarshalContext.getInstance());
  }
 else {
    while (cp.hasNext(iterator)) {
      objectValue=cp.next(iterator,session);
      marshalSingleValue(xPathFragment,marshalRecord,object,objectValue,session,namespaceResolver,ObjectMarshalContext.getInstance());
    }
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Handle the marshal operation for this NodeValue.  Each of the target object's primary key values that are mapped to the collection mapping's fields  (in the XMLCollectionReferenceMapping's source-target key field association list) are retrieved and written out. 
 */
public boolean marshal(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,AbstractSession session,NamespaceResolver namespaceResolver){
  ContainerPolicy cp=xmlCollectionReferenceMapping.getContainerPolicy();
  Object collection=xmlCollectionReferenceMapping.getAttributeAccessor().getAttributeValueFromObject(object);
  if (collection == null) {
    return false;
  }
  Object iterator=cp.iteratorFor(collection);
  if (cp.hasNext(iterator)) {
    XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
    marshalRecord.closeStartGroupingElements(groupingFragment);
  }
 else {
    return false;
  }
  Object objectValue;
  String stringValue=XMLConstants.EMPTY_STRING;
  String newValue;
  QName schemaType;
  if (xmlCollectionReferenceMapping.usesSingleNode()) {
    while (cp.hasNext(iterator)) {
      objectValue=cp.next(iterator,session);
      Object fieldValue=xmlCollectionReferenceMapping.buildFieldValue(objectValue,xmlField,session);
      if (fieldValue == null) {
        if (null != objectValue) {
          XMLField fkField=(XMLField)xmlCollectionReferenceMapping.getSourceToTargetKeyFieldAssociations().get(xmlField);
          fieldValue=marshalRecord.getMarshaller().getXMLContext().getValueByXPath(objectValue,fkField.getXPath(),fkField.getNamespaceResolver(),Object.class);
        }
        if (null == fieldValue) {
          return false;
        }
      }
      schemaType=getSchemaType(xmlField,fieldValue,session);
      newValue=getValueToWrite(schemaType,fieldValue,(XMLConversionManager)session.getDatasourcePlatform().getConversionManager(),namespaceResolver);
      if (newValue != null) {
        stringValue+=newValue;
        if (cp.hasNext(iterator)) {
          stringValue+=SPACE;
        }
      }
    }
    marshalSingleValue(xPathFragment,marshalRecord,object,stringValue,session,namespaceResolver,ObjectMarshalContext.getInstance());
  }
 else {
    while (cp.hasNext(iterator)) {
      objectValue=cp.next(iterator,session);
      marshalSingleValue(xPathFragment,marshalRecord,object,objectValue,session,namespaceResolver,ObjectMarshalContext.getInstance());
    }
  }
  return true;
}