Program: 65135
Project: 65135
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) {
    AbstractNullPolicy wrapperNP=xmlCompositeDirectCollectionMapping.getWrapperNullPolicy();
    if (wrapperNP != null && wrapperNP.getMarshalNullRepresentation().equals(XMLNullRepresentationType.XSI_NIL)) {
      marshalRecord.nilSimple(namespaceResolver);
      return true;
    }
 else {
      return false;
    }
  }
  Object iterator=cp.iteratorFor(collection);
  if (null != iterator && cp.hasNext(iterator)) {
    XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
    marshalRecord.closeStartGroupingElements(groupingFragment);
  }
 else {
    if ((xmlCompositeDirectCollectionMapping.usesSingleNode() && !xmlCompositeDirectCollectionMapping.isDefaultEmptyContainer()) || xmlCompositeDirectCollectionMapping.getWrapperNullPolicy() != null) {
      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()) {
    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) {
    AbstractNullPolicy wrapperNP=xmlCompositeDirectCollectionMapping.getWrapperNullPolicy();
    if (wrapperNP != null && wrapperNP.getMarshalNullRepresentation().equals(XMLNullRepresentationType.XSI_NIL)) {
      marshalRecord.nilSimple(namespaceResolver);
      return true;
    }
 else {
      return false;
    }
  }
  Object iterator=cp.iteratorFor(collection);
  if (null != iterator && cp.hasNext(iterator)) {
    XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
    marshalRecord.closeStartGroupingElements(groupingFragment);
  }
 else {
    if (xmlCompositeDirectCollectionMapping.usesSingleNode() && !xmlCompositeDirectCollectionMapping.isDefaultEmptyContainer()) {
      XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
      marshalRecord.closeStartGroupingElements(groupingFragment);
    }
 else {
      return marshalRecord.emptyCollection(xPathFragment,namespaceResolver,xmlCompositeDirectCollectionMapping.getWrapperNullPolicy() != null);
    }
  }
  Object objectValue;
  StringBuilder stringValueStringBuilder=new StringBuilder();
  String newValue;
  QName schemaType=null;
  if (xmlCompositeDirectCollectionMapping.usesSingleNode()) {
    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;
}