Program: 63483
Project: 63483
Buggy source:
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object value,CoreAbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  if (null == value) {
    return false;
  }
  boolean wasXMLRoot=false;
  XPathFragment xmlRootFragment=null;
  Object originalValue=value;
  Descriptor descriptor;
  ObjectBuilder objectBuilder;
  CoreAbstractSession childSession;
  Marshaller marshaller=marshalRecord.getMarshaller();
  XPathFragment rootFragment;
  if (xmlAnyCollectionMapping.usesXMLRoot() && (value instanceof Root)) {
    xmlRootFragment=new XPathFragment();
    xmlRootFragment.setNamespaceAware(marshalRecord.isNamespaceAware());
    wasXMLRoot=true;
    value=((Root)value).getObject();
    if (null == value) {
      setupFragment(((Root)originalValue),xmlRootFragment,marshalRecord);
      marshalRecord.nilComplex(xmlRootFragment,namespaceResolver);
      return true;
    }
  }
  UnmarshalKeepAsElementPolicy keepAsElementPolicy=xmlAnyCollectionMapping.getKeepAsElementPolicy();
  if (value instanceof String) {
    marshalSimpleValue(xmlRootFragment,marshalRecord,originalValue,object,value,session,namespaceResolver);
  }
 else   if (null != keepAsElementPolicy && (keepAsElementPolicy.isKeepUnknownAsElement() || keepAsElementPolicy.isKeepAllAsElement()) && value instanceof org.w3c.dom.Node) {
    marshalRecord.node((org.w3c.dom.Node)value,marshalRecord.getNamespaceResolver());
  }
 else {
    try {
      childSession=marshaller.getContext().getSession(value);
    }
 catch (    XMLMarshalException e) {
      marshalSimpleValue(xmlRootFragment,marshalRecord,originalValue,object,value,session,namespaceResolver);
      return true;
    }
    descriptor=(Descriptor)childSession.getDescriptor(value);
    objectBuilder=(ObjectBuilder)descriptor.getObjectBuilder();
    List extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session,true,true);
    if (wasXMLRoot) {
      setupFragment(((Root)originalValue),xmlRootFragment,marshalRecord);
    }
    String defaultRootElementString=descriptor.getDefaultRootElement();
    if (!wasXMLRoot && (defaultRootElementString == null)) {
      throw XMLMarshalException.defaultRootElementNotSpecified(descriptor);
    }
 else {
      marshalRecord.beforeContainmentMarshal(value);
      if (xmlRootFragment != null) {
        rootFragment=xmlRootFragment;
      }
 else {
        rootFragment=new XPathFragment(defaultRootElementString);
        if (rootFragment.getNamespaceURI() == null) {
          String uri=descriptor.getNonNullNamespaceResolver().resolveNamespacePrefix(rootFragment.getPrefix());
          rootFragment.setNamespaceURI(uri);
        }
      }
      if (!wasXMLRoot) {
        marshalRecord.setLeafElementType(descriptor.getDefaultRootElementType());
      }
      getXPathNode().startElement(marshalRecord,rootFragment,object,childSession,marshalRecord.getNamespaceResolver(),objectBuilder,value);
      writeExtraNamespaces(extraNamespaces,marshalRecord,session);
      marshalRecord.addXsiTypeAndClassIndicatorIfRequired(descriptor,descriptor,(Field)xmlAnyCollectionMapping.getField(),originalValue,value,wasXMLRoot,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;
  }
  boolean wasXMLRoot=false;
  XPathFragment xmlRootFragment=null;
  Object originalValue=value;
  Descriptor descriptor;
  ObjectBuilder objectBuilder;
  CoreAbstractSession childSession;
  Marshaller marshaller=marshalRecord.getMarshaller();
  XPathFragment rootFragment;
  if (xmlAnyCollectionMapping.usesXMLRoot() && (value instanceof Root)) {
    xmlRootFragment=new XPathFragment();
    xmlRootFragment.setNamespaceAware(marshalRecord.isNamespaceAware());
    wasXMLRoot=true;
    value=((Root)value).getObject();
    if (null == value) {
      setupFragment(((Root)originalValue),xmlRootFragment,marshalRecord);
      marshalRecord.nilComplex(xmlRootFragment,namespaceResolver);
      return true;
    }
  }
  UnmarshalKeepAsElementPolicy keepAsElementPolicy=xmlAnyCollectionMapping.getKeepAsElementPolicy();
  if (value instanceof String) {
    marshalSimpleValue(xmlRootFragment,marshalRecord,originalValue,object,value,session,namespaceResolver);
  }
 else   if (null != keepAsElementPolicy && (keepAsElementPolicy.isKeepUnknownAsElement() || keepAsElementPolicy.isKeepAllAsElement()) && value instanceof org.w3c.dom.Node) {
    marshalRecord.node((org.w3c.dom.Node)value,marshalRecord.getNamespaceResolver());
  }
 else {
    try {
      childSession=marshaller.getContext().getSession(value);
    }
 catch (    XMLMarshalException e) {
      marshalSimpleValue(xmlRootFragment,marshalRecord,originalValue,object,value,session,namespaceResolver);
      return true;
    }
    descriptor=(Descriptor)childSession.getDescriptor(value);
    pushAttributeGroup(marshalRecord,descriptor,getMapping().getAttributeName());
    objectBuilder=(ObjectBuilder)descriptor.getObjectBuilder();
    List extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session,true,true);
    if (wasXMLRoot) {
      setupFragment(((Root)originalValue),xmlRootFragment,marshalRecord);
    }
    String defaultRootElementString=descriptor.getDefaultRootElement();
    if (!wasXMLRoot && (defaultRootElementString == null)) {
      throw XMLMarshalException.defaultRootElementNotSpecified(descriptor);
    }
 else {
      marshalRecord.beforeContainmentMarshal(value);
      if (xmlRootFragment != null) {
        rootFragment=xmlRootFragment;
      }
 else {
        rootFragment=new XPathFragment(defaultRootElementString);
        if (rootFragment.getNamespaceURI() == null) {
          String uri=descriptor.getNonNullNamespaceResolver().resolveNamespacePrefix(rootFragment.getPrefix());
          rootFragment.setNamespaceURI(uri);
        }
      }
      if (!wasXMLRoot) {
        marshalRecord.setLeafElementType(descriptor.getDefaultRootElementType());
      }
      getXPathNode().startElement(marshalRecord,rootFragment,object,childSession,marshalRecord.getNamespaceResolver(),objectBuilder,value);
      writeExtraNamespaces(extraNamespaces,marshalRecord,session);
      pushAttributeGroup(marshalRecord,descriptor,rootFragment.getLocalName());
      marshalRecord.addXsiTypeAndClassIndicatorIfRequired(descriptor,descriptor,(Field)xmlAnyCollectionMapping.getField(),originalValue,value,wasXMLRoot,false);
      objectBuilder.buildRow(marshalRecord,value,session,marshaller,null);
      marshalRecord.afterContainmentMarshal(object,value);
      marshalRecord.endElement(rootFragment,namespaceResolver);
      marshalRecord.removeExtraNamespacesFromNamespaceResolver(extraNamespaces,session);
      marshalRecord.popAttributeGroup();
    }
    marshalRecord.popAttributeGroup();
  }
  return true;
}