Program: 64410
Project: 64410
Buggy source:
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object objectValue,CoreAbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  objectValue=xmlCompositeObjectMapping.convertObjectValueToDataValue(objectValue,session,marshalRecord.getMarshaller());
  if (null == objectValue) {
    return xmlCompositeObjectMapping.getNullPolicy().compositeObjectMarshal(xPathFragment,marshalRecord,object,session,namespaceResolver);
  }
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  if (xPathFragment.hasAttribute) {
    ObjectBuilder tob=(ObjectBuilder)xmlCompositeObjectMapping.getReferenceDescriptor().getObjectBuilder();
    MappingNodeValue textMappingNodeValue=(MappingNodeValue)tob.getRootXPathNode().getTextNode().getMarshalNodeValue();
    Mapping textMapping=textMappingNodeValue.getMapping();
    if (textMapping.isAbstractDirectMapping()) {
      DirectMapping xmlDirectMapping=(DirectMapping)textMapping;
      Object fieldValue=xmlDirectMapping.getFieldValue(xmlDirectMapping.valueFromObject(objectValue,xmlDirectMapping.getField(),session),session,marshalRecord);
      QName schemaType=((Field)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 (null != keepAsElementPolicy && (keepAsElementPolicy.isKeepUnknownAsElement() || keepAsElementPolicy.isKeepAllAsElement()) && 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;
    }
  }
  Descriptor descriptor=(Descriptor)xmlCompositeObjectMapping.getReferenceDescriptor();
  if (descriptor == null) {
    descriptor=(Descriptor)session.getDescriptor(objectValue.getClass());
  }
 else   if (descriptor.hasInheritance()) {
    Class objectValueClass=objectValue.getClass();
    if (!(objectValueClass == descriptor.getJavaClass())) {
      descriptor=(Descriptor)session.getDescriptor(objectValueClass);
    }
  }
  if (descriptor != null) {
    marshalRecord.beforeContainmentMarshal(objectValue);
    ObjectBuilder objectBuilder=(ObjectBuilder)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,(Descriptor)xmlCompositeObjectMapping.getReferenceDescriptor(),(Field)xmlCompositeObjectMapping.getField(),false);
    }
    objectBuilder.buildRow(marshalRecord,objectValue,session,marshalRecord.getMarshaller(),xPathFragment,WriteType.UNDEFINED);
    marshalRecord.afterContainmentMarshal(object,objectValue);
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
    objectBuilder.removeExtraNamespacesFromNamespaceResolver(marshalRecord,extraNamespaces,session);
  }
 else {
    if (Constants.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=((Field)xmlCompositeObjectMapping.getField()).getSchemaTypeForValue(objectValue,session);
    updateNamespaces(schemaType,marshalRecord,((Field)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,CoreAbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  objectValue=xmlCompositeObjectMapping.convertObjectValueToDataValue(objectValue,session,marshalRecord.getMarshaller());
  if (null == objectValue) {
    return xmlCompositeObjectMapping.getNullPolicy().compositeObjectMarshal(xPathFragment,marshalRecord,object,session,namespaceResolver);
  }
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  if (xPathFragment.hasAttribute) {
    ObjectBuilder tob=(ObjectBuilder)xmlCompositeObjectMapping.getReferenceDescriptor().getObjectBuilder();
    MappingNodeValue textMappingNodeValue=(MappingNodeValue)tob.getRootXPathNode().getTextNode().getMarshalNodeValue();
    Mapping textMapping=textMappingNodeValue.getMapping();
    if (textMapping.isAbstractDirectMapping()) {
      DirectMapping xmlDirectMapping=(DirectMapping)textMapping;
      Object fieldValue=xmlDirectMapping.getFieldValue(xmlDirectMapping.valueFromObject(objectValue,xmlDirectMapping.getField(),session),session,marshalRecord);
      QName schemaType=((Field)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 (null != keepAsElementPolicy && (keepAsElementPolicy.isKeepUnknownAsElement() || keepAsElementPolicy.isKeepAllAsElement()) && 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;
    }
  }
  Descriptor descriptor=(Descriptor)xmlCompositeObjectMapping.getReferenceDescriptor();
  if (descriptor == null) {
    descriptor=(Descriptor)session.getDescriptor(objectValue.getClass());
  }
 else   if (descriptor.hasInheritance()) {
    Class objectValueClass=objectValue.getClass();
    if (!(objectValueClass == descriptor.getJavaClass())) {
      descriptor=(Descriptor)session.getDescriptor(objectValueClass);
    }
  }
  if (descriptor != null) {
    marshalRecord.beforeContainmentMarshal(objectValue);
    ObjectBuilder objectBuilder=(ObjectBuilder)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,(Descriptor)xmlCompositeObjectMapping.getReferenceDescriptor(),(Field)xmlCompositeObjectMapping.getField(),false);
    }
    objectBuilder.buildRow(marshalRecord,objectValue,session,marshalRecord.getMarshaller(),xPathFragment);
    marshalRecord.afterContainmentMarshal(object,objectValue);
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
    objectBuilder.removeExtraNamespacesFromNamespaceResolver(marshalRecord,extraNamespaces,session);
  }
 else {
    if (Constants.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=((Field)xmlCompositeObjectMapping.getField()).getSchemaTypeForValue(objectValue,session);
    updateNamespaces(schemaType,marshalRecord,((Field)xmlCompositeObjectMapping.getField()));
    marshalRecord.characters(schemaType,objectValue,null,false);
    if (!(isSelfFragment || xPathFragment.nameIsText())) {
      marshalRecord.endElement(xPathFragment,namespaceResolver);
    }
  }
  return true;
}