Program: 68839
Project: 68839
Buggy source:
/** 
 * Convert the given object to XML and update the given marshal record with that XML Document.
 * @param object the object to marshal
 * @param marshalRecord the marshalRecord to marshal the object to
 * @param descriptor the XMLDescriptor for the object being marshalled
 */
private void marshal(Object object,MarshalRecord marshalRecord,XMLDescriptor descriptor,boolean isXMLRoot){
  if (getMarshalListener() != null) {
    getMarshalListener().beforeMarshal(object);
  }
  if (!isFragment()) {
    String encoding=getEncoding();
    String version=DEFAULT_XML_VERSION;
    if (!isXMLRoot) {
      marshalRecord.setLeafElementType(descriptor.getDefaultRootElementType());
    }
 else {
      XMLRoot root=(XMLRoot)object;
      if (root.getEncoding() != null) {
        encoding=root.getEncoding();
      }
      if (root.getXMLVersion() != null) {
        version=root.getXMLVersion();
      }
    }
    marshalRecord.startDocument(encoding,version);
  }
  NamespaceResolver nr=getNamespaceResolver(object,descriptor,isXMLRoot);
  XPathFragment rootFragment=buildRootFragment(object,descriptor,nr,isXMLRoot);
  nr=updateNamespaceResolver(rootFragment,nr,isXMLRoot);
  boolean shouldWriteTypeAttribute=shouldWriteTypeAttribute(object,descriptor,isXMLRoot);
  String schemaLocation=getSchemaLocation();
  String noNsSchemaLocation=getNoNamespaceSchemaLocation();
  if (isXMLRoot) {
    XMLRoot root=(XMLRoot)object;
    object=root.getObject();
    if (root.getSchemaLocation() != null) {
      schemaLocation=root.getSchemaLocation();
    }
    if (root.getNoNamespaceSchemaLocation() != null) {
      noNsSchemaLocation=root.getNoNamespaceSchemaLocation();
    }
  }
  String xsiPrefix=null;
  if ((null != getSchemaLocation()) || (null != getNoNamespaceSchemaLocation()) || shouldWriteTypeAttribute) {
    if (null == nr) {
      nr=new NamespaceResolver();
    }
    xsiPrefix=nr.resolveNamespaceURI(XMLConstants.SCHEMA_INSTANCE_URL);
    if (null == xsiPrefix) {
      xsiPrefix=XMLConstants.SCHEMA_INSTANCE_PREFIX;
      nr.put(XMLConstants.SCHEMA_INSTANCE_PREFIX,XMLConstants.SCHEMA_INSTANCE_URL);
    }
  }
  TreeObjectBuilder treeObjectBuilder=null;
  AbstractSession session=null;
  if (descriptor != null) {
    session=xmlContext.getSession(object);
    treeObjectBuilder=(TreeObjectBuilder)descriptor.getObjectBuilder();
  }
  if (null != rootFragment) {
    marshalRecord.startPrefixMappings(nr);
    marshalRecord.openStartElement(rootFragment,nr);
    if (null != schemaLocation) {
      marshalRecord.attribute(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_LOCATION,xsiPrefix + "String_Node_Str" + XMLConstants.SCHEMA_LOCATION,schemaLocation);
    }
    if (null != noNsSchemaLocation) {
      marshalRecord.attribute(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.NO_NS_SCHEMA_LOCATION,xsiPrefix + "String_Node_Str" + XMLConstants.NO_NS_SCHEMA_LOCATION,noNsSchemaLocation);
    }
    if (descriptor != null) {
      if (shouldWriteTypeAttribute) {
        writeTypeAttribute(marshalRecord,descriptor,xsiPrefix);
      }
      treeObjectBuilder.marshalAttributes(marshalRecord,object,session);
    }
    marshalRecord.namespaceDeclarations(nr);
    marshalRecord.closeStartElement();
  }
  addRootDescriptorNamespacesToXMLRecord(descriptor,marshalRecord);
  if (treeObjectBuilder != null) {
    treeObjectBuilder.buildRow(marshalRecord,object,(org.eclipse.persistence.internal.sessions.AbstractSession)session,this);
  }
 else   if (isXMLRoot) {
    String value=(String)XMLConversionManager.getDefaultXMLManager().convertObject(object,String.class);
    marshalRecord.characters(value);
  }
  if (null != rootFragment) {
    marshalRecord.endElement(rootFragment,nr);
    marshalRecord.endPrefixMappings(nr);
  }
  if (!isFragment()) {
    marshalRecord.endDocument();
  }
  if (getMarshalListener() != null) {
    getMarshalListener().afterMarshal(object);
  }
}

Fixed version (ground truth):
/** 
 * Convert the given object to XML and update the given marshal record with that XML Document.
 * @param object the object to marshal
 * @param marshalRecord the marshalRecord to marshal the object to
 * @param descriptor the XMLDescriptor for the object being marshalled
 */
private void marshal(Object object,MarshalRecord marshalRecord,XMLDescriptor descriptor,boolean isXMLRoot){
  if (getMarshalListener() != null) {
    getMarshalListener().beforeMarshal(object);
  }
  if (!isFragment()) {
    String encoding=getEncoding();
    String version=DEFAULT_XML_VERSION;
    if (!isXMLRoot) {
      marshalRecord.setLeafElementType(descriptor.getDefaultRootElementType());
    }
 else {
      XMLRoot root=(XMLRoot)object;
      if (root.getEncoding() != null) {
        encoding=root.getEncoding();
      }
      if (root.getXMLVersion() != null) {
        version=root.getXMLVersion();
      }
    }
    marshalRecord.startDocument(encoding,version);
  }
  NamespaceResolver nr=getNamespaceResolver(object,descriptor,isXMLRoot);
  XPathFragment rootFragment=buildRootFragment(object,descriptor,nr,isXMLRoot);
  nr=updateNamespaceResolver(rootFragment,nr,isXMLRoot);
  boolean shouldWriteTypeAttribute=shouldWriteTypeAttribute(object,descriptor,isXMLRoot);
  String schemaLocation=getSchemaLocation();
  String noNsSchemaLocation=getNoNamespaceSchemaLocation();
  if (isXMLRoot) {
    XMLRoot root=(XMLRoot)object;
    object=root.getObject();
    if (root.getSchemaLocation() != null) {
      schemaLocation=root.getSchemaLocation();
    }
    if (root.getNoNamespaceSchemaLocation() != null) {
      noNsSchemaLocation=root.getNoNamespaceSchemaLocation();
    }
  }
  String xsiPrefix=null;
  if ((null != getSchemaLocation()) || (null != getNoNamespaceSchemaLocation()) || shouldWriteTypeAttribute) {
    if (null == nr) {
      nr=new NamespaceResolver();
    }
    xsiPrefix=nr.resolveNamespaceURI(XMLConstants.SCHEMA_INSTANCE_URL);
    if (null == xsiPrefix) {
      xsiPrefix=XMLConstants.SCHEMA_INSTANCE_PREFIX;
      nr.put(XMLConstants.SCHEMA_INSTANCE_PREFIX,XMLConstants.SCHEMA_INSTANCE_URL);
    }
  }
  TreeObjectBuilder treeObjectBuilder=null;
  AbstractSession session=null;
  if (descriptor != null) {
    session=xmlContext.getSession(object);
    treeObjectBuilder=(TreeObjectBuilder)descriptor.getObjectBuilder();
  }
  addRootDescriptorNamespacesToXMLRecord(descriptor,marshalRecord);
  if (null != rootFragment) {
    marshalRecord.startPrefixMappings(nr);
    marshalRecord.openStartElement(rootFragment,nr);
    if (null != schemaLocation) {
      marshalRecord.attribute(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.SCHEMA_LOCATION,xsiPrefix + "String_Node_Str" + XMLConstants.SCHEMA_LOCATION,schemaLocation);
    }
    if (null != noNsSchemaLocation) {
      marshalRecord.attribute(XMLConstants.SCHEMA_INSTANCE_URL,XMLConstants.NO_NS_SCHEMA_LOCATION,xsiPrefix + "String_Node_Str" + XMLConstants.NO_NS_SCHEMA_LOCATION,noNsSchemaLocation);
    }
    if (descriptor != null) {
      if (shouldWriteTypeAttribute) {
        writeTypeAttribute(marshalRecord,descriptor,xsiPrefix);
      }
      treeObjectBuilder.marshalAttributes(marshalRecord,object,session);
    }
    marshalRecord.namespaceDeclarations(nr);
    marshalRecord.closeStartElement();
  }
  if (treeObjectBuilder != null) {
    treeObjectBuilder.buildRow(marshalRecord,object,(org.eclipse.persistence.internal.sessions.AbstractSession)session,this);
  }
 else   if (isXMLRoot) {
    String value=(String)XMLConversionManager.getDefaultXMLManager().convertObject(object,String.class);
    marshalRecord.characters(value);
  }
  if (null != rootFragment) {
    marshalRecord.endElement(rootFragment,nr);
    marshalRecord.endPrefixMappings(nr);
  }
  if (!isFragment()) {
    marshalRecord.endDocument();
  }
  if (getMarshalListener() != null) {
    getMarshalListener().afterMarshal(object);
  }
}