Program: 66503
Project: 66503
Buggy source:
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object value,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  if (null == value) {
    return false;
  }
  boolean wasXMLRoot=false;
  XPathFragment xmlRootFragment=null;
  Object originalValue=value;
  XMLDescriptor descriptor;
  TreeObjectBuilder objectBuilder;
  AbstractSession childSession;
  XMLMarshaller marshaller=marshalRecord.getMarshaller();
  XPathFragment rootFragment;
  if (xmlAnyCollectionMapping.usesXMLRoot() && (value instanceof XMLRoot)) {
    xmlRootFragment=new XPathFragment();
    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=(XMLDescriptor)childSession.getDescriptor(value);
    objectBuilder=(TreeObjectBuilder)descriptor.getObjectBuilder();
    List extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session);
    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 {
      if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
        marshaller.getMarshalListener().beforeMarshal(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);
      if (xmlAnyCollectionMapping.shouldAddXsiType(marshaller,descriptor,originalValue,wasXMLRoot)) {
        String typeValue=descriptor.getSchemaReference().getSchemaContext();
        addTypeAttribute(descriptor,marshalRecord,typeValue);
      }
      objectBuilder.buildRow(marshalRecord,value,session,marshaller,WriteType.UNDEFINED);
      objectBuilder.removeExtraNamespacesFromNamespaceResolver(marshalRecord,extraNamespaces,session);
      marshalRecord.endElement(rootFragment,namespaceResolver);
      if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
        marshaller.getMarshalListener().afterMarshal(value);
      }
    }
  }
  return true;
}

Fixed version (ground truth):
public boolean marshalSingleValue(XPathFragment xPathFragment,MarshalRecord marshalRecord,Object object,Object value,AbstractSession session,NamespaceResolver namespaceResolver,MarshalContext marshalContext){
  if (null == value) {
    return false;
  }
  boolean wasXMLRoot=false;
  XPathFragment xmlRootFragment=null;
  Object originalValue=value;
  XMLDescriptor descriptor;
  TreeObjectBuilder objectBuilder;
  AbstractSession childSession;
  XMLMarshaller marshaller=marshalRecord.getMarshaller();
  XPathFragment rootFragment;
  if (xmlAnyCollectionMapping.usesXMLRoot() && (value instanceof XMLRoot)) {
    xmlRootFragment=new XPathFragment();
    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=(XMLDescriptor)childSession.getDescriptor(value);
    objectBuilder=(TreeObjectBuilder)descriptor.getObjectBuilder();
    List extraNamespaces=objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor,marshalRecord,session);
    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 {
      if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
        marshaller.getMarshalListener().beforeMarshal(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,(XMLField)xmlAnyCollectionMapping.getField(),originalValue,value,wasXMLRoot,false);
      objectBuilder.buildRow(marshalRecord,value,session,marshaller,WriteType.UNDEFINED);
      objectBuilder.removeExtraNamespacesFromNamespaceResolver(marshalRecord,extraNamespaces,session);
      marshalRecord.endElement(rootFragment,namespaceResolver);
      if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
        marshaller.getMarshalListener().afterMarshal(value);
      }
    }
  }
  return true;
}