Program: 64472
Project: 64472
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;
  TreeObjectBuilder objectBuilder;
  CoreAbstractSession childSession;
  XMLMarshaller marshaller=marshalRecord.getMarshaller();
  XPathFragment rootFragment;
  if (xmlAnyCollectionMapping.usesXMLRoot() && (value instanceof XMLRoot)) {
    xmlRootFragment=new XPathFragment();
    xmlRootFragment.setNamespaceAware(marshalRecord.isNamespaceAware());
    wasXMLRoot=true;
    value=((XMLRoot)value).getObject();
    if (null == value) {
      return false;
    }
  }
  UnmarshalKeepAsElementPolicy keepAsElementPolicy=xmlAnyCollectionMapping.getKeepAsElementPolicy();
  if (value instanceof String) {
    marshalSimpleValue(xmlRootFragment,marshalRecord,originalValue,object,value,session,namespaceResolver);
  }
 else   if (((keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT) || (keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) && value instanceof org.w3c.dom.Node) {
    marshalRecord.node((org.w3c.dom.Node)value,marshalRecord.getNamespaceResolver());
  }
 else {
    try {
      childSession=marshaller.getXMLContext().getSession(value);
    }
 catch (    XMLMarshalException e) {
      marshalSimpleValue(xmlRootFragment,marshalRecord,originalValue,object,value,session,namespaceResolver);
      return true;
    }
    descriptor=(Descriptor)childSession.getDescriptor(value);
    objectBuilder=(TreeObjectBuilder)descriptor.getObjectBuilder();
    List extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session,true,true);
    if (wasXMLRoot) {
      Namespace generatedNamespace=setupFragment(((XMLRoot)originalValue),xmlRootFragment,marshalRecord);
      if (generatedNamespace != null) {
        if (extraNamespaces == null) {
          extraNamespaces=new java.util.ArrayList();
        }
        extraNamespaces.add(generatedNamespace);
      }
    }
    String defaultRootElementString=descriptor.getDefaultRootElement();
    if (!wasXMLRoot && (defaultRootElementString == null)) {
      AbstractSessionLog.getLog().log(SessionLog.WARNING,"String_Node_Str",new Object[]{Helper.getShortClassName(this.getClass()),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);
      objectBuilder.addXsiTypeAndClassIndicatorIfRequired(marshalRecord,descriptor,descriptor,(Field)xmlAnyCollectionMapping.getField(),originalValue,value,wasXMLRoot,false);
      objectBuilder.buildRow(marshalRecord,value,session,marshaller,null,WriteType.UNDEFINED);
      marshalRecord.afterContainmentMarshal(object,value);
      marshalRecord.endElement(rootFragment,namespaceResolver);
      objectBuilder.removeExtraNamespacesFromNamespaceResolver(marshalRecord,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;
  TreeObjectBuilder objectBuilder;
  CoreAbstractSession childSession;
  XMLMarshaller marshaller=marshalRecord.getMarshaller();
  XPathFragment rootFragment;
  if (xmlAnyCollectionMapping.usesXMLRoot() && (value instanceof XMLRoot)) {
    xmlRootFragment=new XPathFragment();
    xmlRootFragment.setNamespaceAware(marshalRecord.isNamespaceAware());
    wasXMLRoot=true;
    value=((XMLRoot)value).getObject();
    if (null == value) {
      return false;
    }
  }
  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.getXMLContext().getSession(value);
    }
 catch (    XMLMarshalException e) {
      marshalSimpleValue(xmlRootFragment,marshalRecord,originalValue,object,value,session,namespaceResolver);
      return true;
    }
    descriptor=(Descriptor)childSession.getDescriptor(value);
    objectBuilder=(TreeObjectBuilder)descriptor.getObjectBuilder();
    List extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session,true,true);
    if (wasXMLRoot) {
      Namespace generatedNamespace=setupFragment(((XMLRoot)originalValue),xmlRootFragment,marshalRecord);
      if (generatedNamespace != null) {
        if (extraNamespaces == null) {
          extraNamespaces=new java.util.ArrayList();
        }
        extraNamespaces.add(generatedNamespace);
      }
    }
    String defaultRootElementString=descriptor.getDefaultRootElement();
    if (!wasXMLRoot && (defaultRootElementString == null)) {
      AbstractSessionLog.getLog().log(SessionLog.WARNING,"String_Node_Str",new Object[]{Helper.getShortClassName(this.getClass()),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);
      objectBuilder.addXsiTypeAndClassIndicatorIfRequired(marshalRecord,descriptor,descriptor,(Field)xmlAnyCollectionMapping.getField(),originalValue,value,wasXMLRoot,false);
      objectBuilder.buildRow(marshalRecord,value,session,marshaller,null,WriteType.UNDEFINED);
      marshalRecord.afterContainmentMarshal(object,value);
      marshalRecord.endElement(rootFragment,namespaceResolver);
      objectBuilder.removeExtraNamespacesFromNamespaceResolver(marshalRecord,extraNamespaces,session);
    }
  }
  return true;
}