Program: 64008
Project: 64008
Buggy source:
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object value,CoreAbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  if (null == value) {
    return false;
  }
  Object originalValue=value;
  VariableXPathObjectMapping mapping=(VariableXPathObjectMapping)this.getMapping();
  Descriptor descriptor=(Descriptor)mapping.getReferenceDescriptor();
  if (descriptor.hasInheritance()) {
    Class objectValueClass=value.getClass();
    if (!(objectValueClass == descriptor.getJavaClass())) {
      descriptor=(Descriptor)session.getDescriptor(objectValueClass);
    }
  }
  Marshaller marshaller=marshalRecord.getMarshaller();
  XPathFragment rootFragment;
  ObjectBuilder objectBuilder=(TreeObjectBuilder)descriptor.getObjectBuilder();
  List extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session,true,true);
  String defaultRootElementString=descriptor.getDefaultRootElement();
  marshalRecord.beforeContainmentMarshal(value);
  rootFragment=mapping.getXPathFragmentForValue(value,marshalRecord.getNamespaceResolver(),marshalRecord.isNamespaceAware(),marshalRecord.getNamespaceSeparator());
  if (rootFragment.isGeneratedPrefix()) {
    if (extraNamespaces == null) {
      extraNamespaces=new ArrayList();
    }
    extraNamespaces.add(new Namespace(rootFragment.getPrefix(),rootFragment.getNamespaceURI()));
  }
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  if (mapping.isAttribute()) {
    ObjectBuilder tob=(ObjectBuilder)mapping.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(value,xmlDirectMapping.getField(),session),session,marshalRecord);
      QName schemaType=((Field)xmlDirectMapping.getField()).getSchemaTypeForValue(fieldValue,session);
      marshalRecord.attribute(rootFragment,namespaceResolver,fieldValue,schemaType);
      return true;
    }
 else {
      return textMappingNodeValue.marshalSingleValue(rootFragment,marshalRecord,value,textMapping.getAttributeValueFromObject(value),session,namespaceResolver,marshalContext);
    }
  }
 else {
    marshalRecord.closeStartGroupingElements(groupingFragment);
    getXPathNode().startElement(marshalRecord,rootFragment,object,session,marshalRecord.getNamespaceResolver(),objectBuilder,value);
    writeExtraNamespaces(extraNamespaces,marshalRecord,session);
    marshalRecord.addXsiTypeAndClassIndicatorIfRequired(descriptor,(Descriptor)mapping.getReferenceDescriptor(),(Field)mapping.getField(),originalValue,value,false,false);
    objectBuilder.buildRow(marshalRecord,value,session,marshaller,null);
    marshalRecord.afterContainmentMarshal(object,value);
    marshalRecord.endElement(rootFragment,namespaceResolver);
    marshalRecord.removeExtraNamespacesFromNamespaceResolver(extraNamespaces,session);
  }
  return true;
}

Fixed version (ground truth):
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object value,CoreAbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  if (null == value) {
    return false;
  }
  Object originalValue=value;
  VariableXPathObjectMapping mapping=(VariableXPathObjectMapping)this.getMapping();
  Descriptor descriptor=(Descriptor)mapping.getReferenceDescriptor();
  if (descriptor.hasInheritance()) {
    Class objectValueClass=value.getClass();
    if (!(objectValueClass == descriptor.getJavaClass())) {
      descriptor=(Descriptor)session.getDescriptor(objectValueClass);
    }
  }
  Marshaller marshaller=marshalRecord.getMarshaller();
  XPathFragment rootFragment;
  ObjectBuilder objectBuilder=(ObjectBuilder)descriptor.getObjectBuilder();
  List extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session,true,true);
  String defaultRootElementString=descriptor.getDefaultRootElement();
  marshalRecord.beforeContainmentMarshal(value);
  rootFragment=mapping.getXPathFragmentForValue(value,marshalRecord.getNamespaceResolver(),marshalRecord.isNamespaceAware(),marshalRecord.getNamespaceSeparator());
  if (rootFragment.isGeneratedPrefix()) {
    if (extraNamespaces == null) {
      extraNamespaces=new ArrayList();
    }
    extraNamespaces.add(new Namespace(rootFragment.getPrefix(),rootFragment.getNamespaceURI()));
  }
  XPathFragment groupingFragment=marshalRecord.openStartGroupingElements(namespaceResolver);
  if (mapping.isAttribute()) {
    ObjectBuilder tob=(ObjectBuilder)mapping.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(value,xmlDirectMapping.getField(),session),session,marshalRecord);
      QName schemaType=((Field)xmlDirectMapping.getField()).getSchemaTypeForValue(fieldValue,session);
      marshalRecord.attribute(rootFragment,namespaceResolver,fieldValue,schemaType);
      return true;
    }
 else {
      return textMappingNodeValue.marshalSingleValue(rootFragment,marshalRecord,value,textMapping.getAttributeValueFromObject(value),session,namespaceResolver,marshalContext);
    }
  }
 else {
    marshalRecord.closeStartGroupingElements(groupingFragment);
    getXPathNode().startElement(marshalRecord,rootFragment,object,session,marshalRecord.getNamespaceResolver(),objectBuilder,value);
    writeExtraNamespaces(extraNamespaces,marshalRecord,session);
    marshalRecord.addXsiTypeAndClassIndicatorIfRequired(descriptor,(Descriptor)mapping.getReferenceDescriptor(),(Field)mapping.getField(),originalValue,value,false,false);
    objectBuilder.buildRow(marshalRecord,value,session,marshaller,null);
    marshalRecord.afterContainmentMarshal(object,value);
    marshalRecord.endElement(rootFragment,namespaceResolver);
    marshalRecord.removeExtraNamespacesFromNamespaceResolver(extraNamespaces,session);
  }
  return true;
}