Program: 66119
Project: 66119
Buggy source:
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object objectValue,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  if (xPathFragment.hasLeafElementType()) {
    marshalRecord.setLeafElementType(xPathFragment.getLeafElementType());
  }
  XMLMarshaller marshaller=marshalRecord.getMarshaller();
  Converter converter=xmlCompositeObjectMapping.getConverter();
  if (null != converter) {
    if (converter instanceof XMLConverter) {
      objectValue=((XMLConverter)converter).convertObjectValueToDataValue(objectValue,session,marshaller);
    }
 else {
      objectValue=converter.convertObjectValueToDataValue(objectValue,session);
    }
  }
  if (null == objectValue) {
    return xmlCompositeObjectMapping.getNullPolicy().compositeObjectMarshal(xPathFragment,marshalRecord,object,session,namespaceResolver);
  }
  XMLMarshalListener marshalListener=null;
  if (null != marshaller && null != (marshalListener=marshaller.getMarshalListener())) {
    marshalListener.beforeMarshal(objectValue);
  }
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  boolean isSelfFragment=xPathFragment.isSelfFragment;
  marshalRecord.closeStartGroupingElements(groupingFragment);
  UnmarshalKeepAsElementPolicy keepAsElementPolicy=xmlCompositeObjectMapping.getKeepAsElementPolicy();
  if (((keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT) || (keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) && objectValue instanceof Node) {
    if (isSelfFragment) {
      NodeList children=((org.w3c.dom.Element)objectValue).getChildNodes();
      for (int i=0, size=children.getLength(); i < size; i++) {
        Node next=children.item(i);
        if (next.getNodeType() == Node.ELEMENT_NODE) {
          marshalRecord.node(next,marshalRecord.getNamespaceResolver());
          return true;
        }
      }
    }
 else {
      marshalRecord.node((Node)objectValue,marshalRecord.getNamespaceResolver());
      return true;
    }
  }
  XMLDescriptor descriptor=(XMLDescriptor)xmlCompositeObjectMapping.getReferenceDescriptor();
  if (descriptor == null || descriptor.hasInheritance()) {
    descriptor=(XMLDescriptor)session.getDescriptor(objectValue.getClass());
  }
  if (descriptor != null) {
    TreeObjectBuilder objectBuilder=(TreeObjectBuilder)descriptor.getObjectBuilder();
    if (!isSelfFragment) {
      xPathNode.startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,objectBuilder,objectValue);
    }
    List extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session);
    writeExtraNamespaces(extraNamespaces,marshalRecord,session);
    if (!isSelfFragment) {
      objectBuilder.addXsiTypeAndClassIndicatorIfRequired(marshalRecord,descriptor,(XMLDescriptor)xmlCompositeObjectMapping.getReferenceDescriptor(),(XMLField)xmlCompositeObjectMapping.getField(),false);
    }
    objectBuilder.buildRow(marshalRecord,objectValue,session,marshaller,xPathFragment,WriteType.UNDEFINED);
    if (!isSelfFragment) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
    objectBuilder.removeExtraNamespacesFromNamespaceResolver(marshalRecord,extraNamespaces,session);
  }
 else {
    if (!isSelfFragment) {
      xPathNode.startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,null,objectValue);
    }
    QName schemaType=getSchemaType((XMLField)xmlCompositeObjectMapping.getField(),objectValue,session);
    String stringValue=getValueToWrite(schemaType,objectValue,(XMLConversionManager)session.getDatasourcePlatform().getConversionManager(),namespaceResolver);
    updateNamespaces(schemaType,marshalRecord,((XMLField)xmlCompositeObjectMapping.getField()));
    marshalRecord.characters(stringValue);
    if (!isSelfFragment) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
  }
  if (null != marshalListener) {
    marshalListener.afterMarshal(objectValue);
  }
  return true;
}

Fixed version (ground truth):
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object objectValue,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  if (xPathFragment.hasLeafElementType()) {
    marshalRecord.setLeafElementType(xPathFragment.getLeafElementType());
  }
  XMLMarshaller marshaller=marshalRecord.getMarshaller();
  Converter converter=xmlCompositeObjectMapping.getConverter();
  if (null != converter) {
    if (converter instanceof XMLConverter) {
      objectValue=((XMLConverter)converter).convertObjectValueToDataValue(objectValue,session,marshaller);
    }
 else {
      objectValue=converter.convertObjectValueToDataValue(objectValue,session);
    }
  }
  if (null == objectValue) {
    return xmlCompositeObjectMapping.getNullPolicy().compositeObjectMarshal(xPathFragment,marshalRecord,object,session,namespaceResolver);
  }
  XMLMarshalListener marshalListener=null;
  if (null != marshaller && null != (marshalListener=marshaller.getMarshalListener())) {
    marshalListener.beforeMarshal(objectValue);
  }
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  boolean isSelfFragment=xPathFragment.isSelfFragment;
  marshalRecord.closeStartGroupingElements(groupingFragment);
  UnmarshalKeepAsElementPolicy keepAsElementPolicy=xmlCompositeObjectMapping.getKeepAsElementPolicy();
  if (((keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT) || (keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) && objectValue instanceof Node) {
    if (isSelfFragment) {
      NodeList children=((org.w3c.dom.Element)objectValue).getChildNodes();
      for (int i=0, size=children.getLength(); i < size; i++) {
        Node next=children.item(i);
        if (next.getNodeType() == Node.ELEMENT_NODE) {
          marshalRecord.node(next,marshalRecord.getNamespaceResolver());
          return true;
        }
      }
    }
 else {
      marshalRecord.node((Node)objectValue,marshalRecord.getNamespaceResolver());
      return true;
    }
  }
  XMLDescriptor descriptor=(XMLDescriptor)xmlCompositeObjectMapping.getReferenceDescriptor();
  if (descriptor == null || descriptor.hasInheritance()) {
    descriptor=(XMLDescriptor)session.getDescriptor(objectValue.getClass());
  }
  if (descriptor != null) {
    TreeObjectBuilder objectBuilder=(TreeObjectBuilder)descriptor.getObjectBuilder();
    if (!isSelfFragment) {
      xPathNode.startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,objectBuilder,objectValue);
    }
    List extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session);
    writeExtraNamespaces(extraNamespaces,marshalRecord,session);
    if (!isSelfFragment) {
      objectBuilder.addXsiTypeAndClassIndicatorIfRequired(marshalRecord,descriptor,(XMLDescriptor)xmlCompositeObjectMapping.getReferenceDescriptor(),(XMLField)xmlCompositeObjectMapping.getField(),false);
    }
    objectBuilder.buildRow(marshalRecord,objectValue,session,marshaller,xPathFragment,WriteType.UNDEFINED);
    if (!isSelfFragment) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
    objectBuilder.removeExtraNamespacesFromNamespaceResolver(marshalRecord,extraNamespaces,session);
  }
 else {
    if (!isSelfFragment) {
      xPathNode.startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,null,objectValue);
    }
    QName schemaType=getSchemaType((XMLField)xmlCompositeObjectMapping.getField(),objectValue,session);
    String stringValue=getValueToWrite(schemaType,objectValue,(XMLConversionManager)session.getDatasourcePlatform().getConversionManager(),marshalRecord);
    updateNamespaces(schemaType,marshalRecord,((XMLField)xmlCompositeObjectMapping.getField()));
    marshalRecord.characters(stringValue);
    if (!isSelfFragment) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
  }
  if (null != marshalListener) {
    marshalListener.afterMarshal(objectValue);
  }
  return true;
}