Program: 64722
Project: 64722
Buggy source:
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object objectValue,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  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);
  }
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  if (xPathFragment.hasAttribute) {
    TreeObjectBuilder tob=(TreeObjectBuilder)xmlCompositeObjectMapping.getReferenceDescriptor().getObjectBuilder();
    MappingNodeValue textMappingNodeValue=(MappingNodeValue)tob.getRootXPathNode().getTextNode().getMarshalNodeValue();
    DatabaseMapping textMapping=textMappingNodeValue.getMapping();
    if (textMapping.isDirectToFieldMapping()) {
      XMLDirectMapping xmlDirectMapping=(XMLDirectMapping)textMapping;
      Object fieldValue=xmlDirectMapping.getFieldValue(xmlDirectMapping.valueFromObject(objectValue,xmlDirectMapping.getField(),session),session,marshalRecord);
      QName schemaType=((XMLField)xmlDirectMapping.getField()).getSchemaTypeForValue(fieldValue,session);
      marshalRecord.attribute(xPathFragment,namespaceResolver,fieldValue,schemaType);
      marshalRecord.closeStartGroupingElements(groupingFragment);
      return true;
    }
 else {
      return textMappingNodeValue.marshalSingleValue(xPathFragment,marshalRecord,objectValue,textMapping.getAttributeValueFromObject(objectValue),session,namespaceResolver,marshalContext);
    }
  }
  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();
      int childrenLength=children.getLength();
      for (int i=0; i < childrenLength; i++) {
        Node next=children.item(i);
        if (next.getNodeType() == Node.ELEMENT_NODE) {
          marshalRecord.node(next,marshalRecord.getNamespaceResolver());
          return true;
        }
 else         if (next.getNodeType() == Node.TEXT_NODE) {
          marshalRecord.characters(((Text)next).getNodeValue());
          return true;
        }
      }
      return false;
    }
 else {
      marshalRecord.node((Node)objectValue,marshalRecord.getNamespaceResolver());
      return true;
    }
  }
  XMLDescriptor descriptor=(XMLDescriptor)xmlCompositeObjectMapping.getReferenceDescriptor();
  if (descriptor == null) {
    descriptor=(XMLDescriptor)session.getDescriptor(objectValue.getClass());
  }
 else   if (descriptor.hasInheritance()) {
    Class objectValueClass=objectValue.getClass();
    if (!(objectValueClass == descriptor.getJavaClass())) {
      descriptor=(XMLDescriptor)session.getDescriptor(objectValueClass);
    }
  }
  if (descriptor != null) {
    marshalRecord.beforeContainmentMarshal(objectValue);
    TreeObjectBuilder objectBuilder=(TreeObjectBuilder)descriptor.getObjectBuilder();
    if (!(isSelfFragment || xPathFragment.nameIsText)) {
      xPathNode.startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,objectBuilder,objectValue);
    }
    List extraNamespaces=null;
    if (!marshalRecord.hasEqualNamespaceResolvers()) {
      extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session,true,false);
      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);
    marshalRecord.afterContainmentMarshal(object,objectValue);
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
    objectBuilder.removeExtraNamespacesFromNamespaceResolver(marshalRecord,extraNamespaces,session);
  }
 else {
    if (XMLConstants.UNKNOWN_OR_TRANSIENT_CLASS.equals(xmlCompositeObjectMapping.getReferenceClassName())) {
      throw XMLMarshalException.descriptorNotFoundInProject(objectValue.getClass().getName());
    }
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      xPathNode.startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,null,objectValue);
    }
    QName schemaType=((XMLField)xmlCompositeObjectMapping.getField()).getSchemaTypeForValue(objectValue,session);
    updateNamespaces(schemaType,marshalRecord,((XMLField)xmlCompositeObjectMapping.getField()));
    marshalRecord.characters(schemaType,objectValue,null,false);
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
  }
  return true;
}

Fixed version (ground truth):
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object objectValue,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  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);
  }
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  if (xPathFragment.hasAttribute) {
    TreeObjectBuilder tob=(TreeObjectBuilder)xmlCompositeObjectMapping.getReferenceDescriptor().getObjectBuilder();
    MappingNodeValue textMappingNodeValue=(MappingNodeValue)tob.getRootXPathNode().getTextNode().getMarshalNodeValue();
    DatabaseMapping textMapping=textMappingNodeValue.getMapping();
    if (textMapping.isDirectToFieldMapping()) {
      XMLDirectMapping xmlDirectMapping=(XMLDirectMapping)textMapping;
      Object fieldValue=xmlDirectMapping.getFieldValue(xmlDirectMapping.valueFromObject(objectValue,xmlDirectMapping.getField(),session),session,marshalRecord);
      QName schemaType=((XMLField)xmlDirectMapping.getField()).getSchemaTypeForValue(fieldValue,session);
      marshalRecord.attribute(xPathFragment,namespaceResolver,fieldValue,schemaType);
      marshalRecord.closeStartGroupingElements(groupingFragment);
      return true;
    }
 else {
      return textMappingNodeValue.marshalSingleValue(xPathFragment,marshalRecord,objectValue,textMapping.getAttributeValueFromObject(objectValue),session,namespaceResolver,marshalContext);
    }
  }
  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, childrenLength=children.getLength(); i < childrenLength; i++) {
        Node next=children.item(i);
        short nodeType=next.getNodeType();
        if (nodeType == Node.ELEMENT_NODE) {
          marshalRecord.node(next,marshalRecord.getNamespaceResolver());
          return true;
        }
 else         if (nodeType == Node.TEXT_NODE) {
          marshalRecord.characters(((Text)next).getNodeValue());
          return true;
        }
      }
      return false;
    }
 else {
      marshalRecord.node((Node)objectValue,marshalRecord.getNamespaceResolver());
      return true;
    }
  }
  XMLDescriptor descriptor=(XMLDescriptor)xmlCompositeObjectMapping.getReferenceDescriptor();
  if (descriptor == null) {
    descriptor=(XMLDescriptor)session.getDescriptor(objectValue.getClass());
  }
 else   if (descriptor.hasInheritance()) {
    Class objectValueClass=objectValue.getClass();
    if (!(objectValueClass == descriptor.getJavaClass())) {
      descriptor=(XMLDescriptor)session.getDescriptor(objectValueClass);
    }
  }
  if (descriptor != null) {
    marshalRecord.beforeContainmentMarshal(objectValue);
    TreeObjectBuilder objectBuilder=(TreeObjectBuilder)descriptor.getObjectBuilder();
    if (!(isSelfFragment || xPathFragment.nameIsText)) {
      xPathNode.startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,objectBuilder,objectValue);
    }
    List extraNamespaces=null;
    if (!marshalRecord.hasEqualNamespaceResolvers()) {
      extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session,true,false);
      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);
    marshalRecord.afterContainmentMarshal(object,objectValue);
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
    objectBuilder.removeExtraNamespacesFromNamespaceResolver(marshalRecord,extraNamespaces,session);
  }
 else {
    if (XMLConstants.UNKNOWN_OR_TRANSIENT_CLASS.equals(xmlCompositeObjectMapping.getReferenceClassName())) {
      throw XMLMarshalException.descriptorNotFoundInProject(objectValue.getClass().getName());
    }
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      xPathNode.startElement(marshalRecord,xPathFragment,object,session,namespaceResolver,null,objectValue);
    }
    QName schemaType=((XMLField)xmlCompositeObjectMapping.getField()).getSchemaTypeForValue(objectValue,session);
    updateNamespaces(schemaType,marshalRecord,((XMLField)xmlCompositeObjectMapping.getField()));
    marshalRecord.characters(schemaType,objectValue,null,false);
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
  }
  return true;
}