Program: 66496
Project: 66496
Buggy source:
/** 
 * INTERNAL: Saves the DataObject as an XML document with the specified root element. Same as save(createDocument(dataObject, rootElementURI, rootElementName), writer, null);
 * @param dataObject specifies DataObject to be saved
 * @param rootElementURI the Target Namespace URI of the root XML element
 * @param rootElementName the Name of the root XML element
 * @param writer specifies the Writer to write to.
 * @throws IOException for stream exceptions.
 * @throws IllegalArgumentException if the dataObject treeis not closed or has no container.
 */
private void save(DataObject rootObject,String rootElementURI,String rootElementName,Writer writer) throws XMLMarshalException {
  SDOXMLDocument xmlDocument=(SDOXMLDocument)createDocument(rootObject,rootElementURI,rootElementName);
  XMLMarshaller anXMLMarshaller=getXmlMarshaller();
  anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration());
  WriterRecord writerRecord;
  if (anXMLMarshaller.isFormattedOutput()) {
    writerRecord=new FormattedWriterRecord();
  }
 else {
    writerRecord=new WriterRecord();
  }
  writerRecord.setWriter(writer);
  writerRecord.setMarshaller(anXMLMarshaller);
  ((SDOMarshalListener)anXMLMarshaller.getMarshalListener()).setMarshalledObject(rootObject);
  ((SDOMarshalListener)anXMLMarshaller.getMarshalListener()).setMarshalledObjectRootQName(new QName(rootElementURI,rootElementName));
  ((SDOMarshalListener)anXMLMarshaller.getMarshalListener()).setRootMarshalReocrd(writerRecord);
  anXMLMarshaller.marshal(xmlDocument,writerRecord);
  try {
    writer.flush();
  }
 catch (  IOException ex) {
    throw XMLMarshalException.marshalException(ex);
  }
}

Fixed version (ground truth):
/** 
 * INTERNAL: Saves the DataObject as an XML document with the specified root element. Same as save(createDocument(dataObject, rootElementURI, rootElementName), writer, null);
 * @param dataObject specifies DataObject to be saved
 * @param rootElementURI the Target Namespace URI of the root XML element
 * @param rootElementName the Name of the root XML element
 * @param writer specifies the Writer to write to.
 * @throws IOException for stream exceptions.
 * @throws IllegalArgumentException if the dataObject treeis not closed or has no container.
 */
private void save(DataObject rootObject,String rootElementURI,String rootElementName,Writer writer) throws XMLMarshalException {
  SDOXMLDocument xmlDocument=(SDOXMLDocument)createDocument(rootObject,rootElementURI,rootElementName);
  XMLMarshaller anXMLMarshaller=getXmlMarshaller();
  anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration());
  WriterRecord writerRecord;
  if (anXMLMarshaller.isFormattedOutput()) {
    writerRecord=new FormattedWriterRecord();
  }
 else {
    writerRecord=new WriterRecord();
  }
  writerRecord.setWriter(writer);
  writerRecord.setMarshaller(anXMLMarshaller);
  ((SDOMarshalListener)anXMLMarshaller.getMarshalListener()).setMarshalledObject(rootObject);
  ((SDOMarshalListener)anXMLMarshaller.getMarshalListener()).setMarshalledObjectRootQName(new QName(rootElementURI,rootElementName));
  ((SDOMarshalListener)anXMLMarshaller.getMarshalListener()).setRootMarshalRecord(writerRecord);
  anXMLMarshaller.marshal(xmlDocument,writerRecord);
  try {
    writer.flush();
  }
 catch (  IOException ex) {
    throw XMLMarshalException.marshalException(ex);
  }
}