Program: 67352
Project: 67352
Buggy source:
public boolean marshal(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  if (xmlCompositeObjectMapping.isReadOnly()) {
    return false;
  }
  if (xPathFragment.hasLeafElementType()) {
    marshalRecord.setLeafElementType(xPathFragment.getLeafElementType());
  }
  Object objectValue=marshalContext.getAttributeValue(object,xmlCompositeObjectMapping);
  XMLMarshaller marshaller=marshalRecord.getMarshaller();
  if (xmlCompositeObjectMapping.getConverter() != null) {
    Converter converter=xmlCompositeObjectMapping.getConverter();
    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);
  }
  if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
    marshaller.getMarshalListener().beforeMarshal(objectValue);
  }
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  marshalRecord.closeStartGroupingElements(groupingFragment);
  UnmarshalKeepAsElementPolicy keepAsElementPolicy=xmlCompositeObjectMapping.getKeepAsElementPolicy();
  if (((keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT) || (keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) && objectValue instanceof Node) {
    if (xPathFragment.isSelfFragment) {
      NodeList children=((org.w3c.dom.Element)objectValue).getChildNodes();
      for (int i=0; i < children.getLength(); 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)session.getDescriptor(objectValue);
  if (descriptor != null) {
    TreeObjectBuilder objectBuilder=(TreeObjectBuilder)descriptor.getObjectBuilder();
    if (!xPathFragment.isSelfFragment()) {
      getXPathNode().startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,objectBuilder,objectValue);
    }
    List extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session);
    writeExtraNamespaces(extraNamespaces,marshalRecord,session);
    if ((xmlCompositeObjectMapping.getReferenceDescriptor() == null) && (descriptor.getSchemaReference() != null)) {
      addTypeAttributeIfNeeded(descriptor,xmlCompositeObjectMapping,marshalRecord);
    }
    objectBuilder.buildRow(marshalRecord,objectValue,session,marshaller);
    if (!xPathFragment.isSelfFragment()) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
    objectBuilder.removeExtraNamespacesFromNamespaceResolver(marshalRecord,extraNamespaces,session);
  }
 else {
    if (!xPathFragment.isSelfFragment()) {
      getXPathNode().startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,null,objectValue);
    }
    String stringValue=null;
    if (objectValue instanceof String) {
      stringValue=(String)objectValue;
    }
 else {
      QName schemaType=getSchemaType((XMLField)xmlCompositeObjectMapping.getField(),objectValue,session);
      stringValue=getValueToWrite(schemaType,objectValue,(XMLConversionManager)session.getDatasourcePlatform().getConversionManager(),namespaceResolver);
      updateNamespaces(schemaType,marshalRecord);
    }
    marshalRecord.characters(stringValue);
    if (!xPathFragment.isSelfFragment()) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
  }
  if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
    marshaller.getMarshalListener().afterMarshal(objectValue);
  }
  return true;
}

Fixed version (ground truth):
public boolean marshal(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  if (xmlCompositeObjectMapping.isReadOnly()) {
    return false;
  }
  if (xPathFragment.hasLeafElementType()) {
    marshalRecord.setLeafElementType(xPathFragment.getLeafElementType());
  }
  Object objectValue=marshalContext.getAttributeValue(object,xmlCompositeObjectMapping);
  XMLMarshaller marshaller=marshalRecord.getMarshaller();
  if (xmlCompositeObjectMapping.getConverter() != null) {
    Converter converter=xmlCompositeObjectMapping.getConverter();
    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);
  }
  if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
    marshaller.getMarshalListener().beforeMarshal(objectValue);
  }
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  marshalRecord.closeStartGroupingElements(groupingFragment);
  UnmarshalKeepAsElementPolicy keepAsElementPolicy=xmlCompositeObjectMapping.getKeepAsElementPolicy();
  if (((keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT) || (keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) && objectValue instanceof Node) {
    if (xPathFragment.isSelfFragment) {
      NodeList children=((org.w3c.dom.Element)objectValue).getChildNodes();
      for (int i=0; i < children.getLength(); 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)session.getDescriptor(objectValue);
  if (descriptor != null) {
    TreeObjectBuilder objectBuilder=(TreeObjectBuilder)descriptor.getObjectBuilder();
    if (!xPathFragment.isSelfFragment()) {
      getXPathNode().startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,objectBuilder,objectValue);
    }
    List extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session);
    writeExtraNamespaces(extraNamespaces,marshalRecord,session);
    if ((xmlCompositeObjectMapping.getReferenceDescriptor() == null) && (descriptor.getSchemaReference() != null)) {
      addTypeAttributeIfNeeded(descriptor,xmlCompositeObjectMapping,marshalRecord);
    }
    objectBuilder.buildRow(marshalRecord,objectValue,session,marshaller);
    if (!xPathFragment.isSelfFragment()) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
    objectBuilder.removeExtraNamespacesFromNamespaceResolver(marshalRecord,extraNamespaces,session);
  }
 else {
    if (!xPathFragment.isSelfFragment()) {
      getXPathNode().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 (!xPathFragment.isSelfFragment()) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
  }
  if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
    marshaller.getMarshalListener().afterMarshal(objectValue);
  }
  return true;
}