Program: 65665
Project: 65665
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,AbstractSession session,NamespaceResolver namespaceResolver){
  if (xmlCompositeDirectCollectionMapping.isReadOnly()) {
    return false;
  }
  ContainerPolicy cp=getContainerPolicy();
  Object collection=xmlCompositeDirectCollectionMapping.getAttributeAccessor().getAttributeValueFromObject(object);
  if (null == collection) {
    return false;
  }
  Object iterator=cp.iteratorFor(collection);
  if (cp.hasNext(iterator)) {
    XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
    marshalRecord.closeStartGroupingElements(groupingFragment);
  }
 else {
    return false;
  }
  Object objectValue;
  StringBuilder stringValueStringBuilder=new StringBuilder();
  String newValue;
  QName schemaType=null;
  if (xmlCompositeDirectCollectionMapping.usesSingleNode() && marshalRecord.supportsSingleNode()) {
    if (xPathFragment != null && !xPathFragment.isAttribute() && !xPathFragment.nameIsText) {
      marshalRecord.openStartElement(xPathFragment,namespaceResolver);
    }
    while (cp.hasNext(iterator)) {
      objectValue=cp.next(iterator,session);
      if (xmlCompositeDirectCollectionMapping.hasValueConverter()) {
        if (xmlCompositeDirectCollectionMapping.getValueConverter() instanceof XMLConverter) {
          objectValue=((XMLConverter)xmlCompositeDirectCollectionMapping.getValueConverter()).convertObjectValueToDataValue(objectValue,session,marshalRecord.getMarshaller());
        }
 else {
          objectValue=xmlCompositeDirectCollectionMapping.getValueConverter().convertObjectValueToDataValue(objectValue,session);
        }
      }
      schemaType=getSchemaType((XMLField)xmlCompositeDirectCollectionMapping.getField(),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,AbstractSession session,NamespaceResolver namespaceResolver){
  if (xmlCompositeDirectCollectionMapping.isReadOnly()) {
    return false;
  }
  ContainerPolicy cp=getContainerPolicy();
  Object collection=xmlCompositeDirectCollectionMapping.getAttributeAccessor().getAttributeValueFromObject(object);
  if (null == collection) {
    return false;
  }
  Object iterator=cp.iteratorFor(collection);
  if (cp.hasNext(iterator)) {
    XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
    marshalRecord.closeStartGroupingElements(groupingFragment);
  }
 else {
    return false;
  }
  Object objectValue;
  StringBuilder stringValueStringBuilder=new StringBuilder();
  String newValue;
  QName schemaType=null;
  if (xmlCompositeDirectCollectionMapping.usesSingleNode() && marshalRecord.supportsSingleNode()) {
    if (xPathFragment != null && !xPathFragment.isAttribute() && !xPathFragment.nameIsText) {
      marshalRecord.openStartElement(xPathFragment,namespaceResolver);
    }
    while (cp.hasNext(iterator)) {
      objectValue=cp.next(iterator,session);
      if (xmlCompositeDirectCollectionMapping.hasValueConverter()) {
        if (xmlCompositeDirectCollectionMapping.getValueConverter() instanceof XMLConverter) {
          objectValue=((XMLConverter)xmlCompositeDirectCollectionMapping.getValueConverter()).convertObjectValueToDataValue(objectValue,session,marshalRecord.getMarshaller());
        }
 else {
          objectValue=xmlCompositeDirectCollectionMapping.getValueConverter().convertObjectValueToDataValue(objectValue,session);
        }
      }
      schemaType=getSchemaType((XMLField)xmlCompositeDirectCollectionMapping.getField(),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 {
    XPathFragment textXPathFragment=null;
    if (xPathFragment.nameIsText() && marshalRecord.getTextWrapperFragment() != null && xPathFragment.getXMLField().getXPathFragment() == xPathFragment) {
      textXPathFragment=marshalRecord.getTextWrapperFragment();
    }
    if (textXPathFragment != null) {
      marshalRecord.openStartElement(textXPathFragment,namespaceResolver);
    }
    marshalRecord.startCollection();
    while (cp.hasNext(iterator)) {
      objectValue=cp.next(iterator,session);
      marshalSingleValue(xPathFragment,marshalRecord,object,objectValue,session,namespaceResolver,ObjectMarshalContext.getInstance());
    }
    if (textXPathFragment != null) {
      marshalRecord.endElement(textXPathFragment,namespaceResolver);
    }
    marshalRecord.endCollection();
  }
  return true;
}