Program: 63980
Project: 63980
Buggy source:
/** 
 * Override the method in XPathNode such that the marshaller can be set on the marshalRecord - this is required for XMLConverter usage.
 */
public boolean marshal(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,CoreAbstractSession session,NamespaceResolver namespaceResolver){
  if (xmlCompositeDirectCollectionMapping.isReadOnly()) {
    return false;
  }
  CoreContainerPolicy cp=getContainerPolicy();
  Object collection=xmlCompositeDirectCollectionMapping.getAttributeAccessor().getAttributeValueFromObject(object);
  if (null == collection) {
    AbstractNullPolicy wrapperNP=xmlCompositeDirectCollectionMapping.getWrapperNullPolicy();
    if (wrapperNP != null && wrapperNP.getMarshalNullRepresentation() == XMLNullRepresentationType.XSI_NIL) {
      marshalRecord.nilSimple(namespaceResolver);
      return true;
    }
 else {
      return false;
    }
  }
  Object iterator=cp.iteratorFor(collection);
  Field xmlField=(Field)xmlCompositeDirectCollectionMapping.getField();
  if (null != iterator && cp.hasNext(iterator)) {
    XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
    marshalRecord.closeStartGroupingElements(groupingFragment);
  }
 else {
    if (xmlField.usesSingleNode() && !xmlCompositeDirectCollectionMapping.isDefaultEmptyContainer()) {
      XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
      marshalRecord.closeStartGroupingElements(groupingFragment);
    }
 else {
      return marshalRecord.emptyCollection(xPathFragment,namespaceResolver,xmlCompositeDirectCollectionMapping.getWrapperNullPolicy() != null);
    }
  }
  Object objectValue;
  if (xmlField.usesSingleNode()) {
    StringBuilder stringValueStringBuilder=new StringBuilder();
    String newValue;
    QName schemaType=null;
    if (xPathFragment != null && !xPathFragment.isAttribute() && !xPathFragment.nameIsText) {
      marshalRecord.openStartElement(xPathFragment,namespaceResolver);
    }
    while (cp.hasNext(iterator)) {
      objectValue=cp.next(iterator,session);
      objectValue=xmlCompositeDirectCollectionMapping.convertObjectValueToDataValue(objectValue,session,marshalRecord.getMarshaller());
      schemaType=xmlField.getSchemaTypeForValue(objectValue,session);
      newValue=marshalRecord.getValueToWrite(schemaType,objectValue,(XMLConversionManager)session.getDatasourcePlatform().getConversionManager());
      if (null != newValue) {
        stringValueStringBuilder.append(newValue);
        if (cp.hasNext(iterator)) {
          stringValueStringBuilder.append(SPACE);
        }
      }
    }
    XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
    if (xPathFragment != null && xPathFragment.isAttribute()) {
      marshalRecord.attribute(xPathFragment,namespaceResolver,stringValueStringBuilder.toString());
      marshalRecord.closeStartGroupingElements(groupingFragment);
    }
 else {
      marshalRecord.closeStartGroupingElements(groupingFragment);
      if (xmlCompositeDirectCollectionMapping.isCDATA()) {
        marshalRecord.cdata(stringValueStringBuilder.toString());
      }
 else {
        marshalRecord.characters(stringValueStringBuilder.toString());
        if (xPathFragment != null && !xPathFragment.isAttribute() && !xPathFragment.nameIsText) {
          marshalRecord.endElement(xPathFragment,namespaceResolver);
        }
      }
    }
  }
 else {
    marshalRecord.startCollection();
    while (cp.hasNext(iterator)) {
      objectValue=cp.next(iterator,session);
      marshalSingleValue(xPathFragment,marshalRecord,object,objectValue,session,namespaceResolver,ObjectMarshalContext.getInstance());
    }
    marshalRecord.endCollection();
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Override the method in XPathNode such that the marshaller can be set on the marshalRecord - this is required for XMLConverter usage.
 */
public boolean marshal(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,CoreAbstractSession session,NamespaceResolver namespaceResolver){
  if (xmlCompositeDirectCollectionMapping.isReadOnly()) {
    return false;
  }
  CoreContainerPolicy cp=getContainerPolicy();
  Object collection=xmlCompositeDirectCollectionMapping.getAttributeAccessor().getAttributeValueFromObject(object);
  if (null == collection) {
    AbstractNullPolicy wrapperNP=xmlCompositeDirectCollectionMapping.getWrapperNullPolicy();
    if (wrapperNP != null && wrapperNP.getMarshalNullRepresentation() == XMLNullRepresentationType.XSI_NIL) {
      marshalRecord.nilSimple(namespaceResolver);
      return true;
    }
 else {
      return false;
    }
  }
  Object iterator=cp.iteratorFor(collection);
  Field xmlField=(Field)xmlCompositeDirectCollectionMapping.getField();
  if (null != iterator && cp.hasNext(iterator)) {
    XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
    marshalRecord.closeStartGroupingElements(groupingFragment);
  }
 else {
    if (xmlField.usesSingleNode() && !xmlCompositeDirectCollectionMapping.isDefaultEmptyContainer()) {
      XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
      marshalRecord.closeStartGroupingElements(groupingFragment);
    }
 else {
      return marshalRecord.emptyCollection(xPathFragment,namespaceResolver,xmlCompositeDirectCollectionMapping.getWrapperNullPolicy() != null);
    }
  }
  Object objectValue;
  if (xmlField.usesSingleNode()) {
    StringBuilder stringValueStringBuilder=new StringBuilder();
    String newValue;
    QName schemaType=null;
    if (xPathFragment != null && !xPathFragment.isAttribute() && !xPathFragment.nameIsText) {
      marshalRecord.openStartElement(xPathFragment,namespaceResolver);
    }
    while (cp.hasNext(iterator)) {
      objectValue=cp.next(iterator,session);
      objectValue=xmlCompositeDirectCollectionMapping.convertObjectValueToDataValue(objectValue,session,marshalRecord.getMarshaller());
      schemaType=xmlField.getSchemaTypeForValue(objectValue,session);
      newValue=marshalRecord.getValueToWrite(schemaType,objectValue,(ConversionManager)session.getDatasourcePlatform().getConversionManager());
      if (null != newValue) {
        stringValueStringBuilder.append(newValue);
        if (cp.hasNext(iterator)) {
          stringValueStringBuilder.append(SPACE);
        }
      }
    }
    XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
    if (xPathFragment != null && xPathFragment.isAttribute()) {
      marshalRecord.attribute(xPathFragment,namespaceResolver,stringValueStringBuilder.toString());
      marshalRecord.closeStartGroupingElements(groupingFragment);
    }
 else {
      marshalRecord.closeStartGroupingElements(groupingFragment);
      if (xmlCompositeDirectCollectionMapping.isCDATA()) {
        marshalRecord.cdata(stringValueStringBuilder.toString());
      }
 else {
        marshalRecord.characters(stringValueStringBuilder.toString());
        if (xPathFragment != null && !xPathFragment.isAttribute() && !xPathFragment.nameIsText) {
          marshalRecord.endElement(xPathFragment,namespaceResolver);
        }
      }
    }
  }
 else {
    marshalRecord.startCollection();
    while (cp.hasNext(iterator)) {
      objectValue=cp.next(iterator,session);
      marshalSingleValue(xPathFragment,marshalRecord,object,objectValue,session,namespaceResolver,ObjectMarshalContext.getInstance());
    }
    marshalRecord.endCollection();
  }
  return true;
}