Program: 63781
Project: 63781
Buggy source:
private void marshal(Object object,Writer writer,ABSTRACT_SESSION session,DESCRIPTOR xmlDescriptor) throws XMLMarshalException {
  if ((object == null) || (writer == null)) {
    throw XMLMarshalException.nullArgumentException();
  }
  boolean isXMLRoot=false;
  String version=DEFAULT_XML_VERSION;
  String encoding=getEncoding();
  String callbackName=null;
  if (object instanceof JSONWithPadding) {
    callbackName=((JSONWithPadding)object).getCallbackName();
    object=((JSONWithPadding)object).getObject();
    if (object == null) {
      throw XMLMarshalException.nullArgumentException();
    }
  }
  if (object instanceof Root) {
    isXMLRoot=true;
    Root xroot=(Root)object;
    version=xroot.getXMLVersion() != null ? xroot.getXMLVersion() : version;
    encoding=xroot.getEncoding() != null ? xroot.getEncoding() : encoding;
  }
  MarshalRecord writerRecord;
  writer=wrapWriter(writer);
  if (isFormattedOutput()) {
    if (isApplicationJSON()) {
      writerRecord=new JSONFormattedWriterRecord(writer,callbackName);
    }
 else {
      writerRecord=new FormattedWriterRecord();
      ((FormattedWriterRecord)writerRecord).setWriter(writer);
    }
  }
 else {
    if (isApplicationJSON()) {
      writerRecord=new JSONWriterRecord(writer,callbackName);
    }
 else {
      writerRecord=new WriterRecord();
      ((WriterRecord)writerRecord).setWriter(writer);
    }
  }
  writerRecord.setMarshaller(this);
  String rootName=null;
  String rootNamespace=null;
  if (isXMLRoot) {
    rootName=((Root)object).getLocalName();
    rootNamespace=((Root)object).getNamespaceURI();
    if (session == null || xmlDescriptor == null) {
      try {
        session=context.getSession(((Root)object).getObject());
        if (session != null) {
          xmlDescriptor=getDescriptor(((Root)object).getObject(),session);
        }
      }
 catch (      XMLMarshalException marshalException) {
        if (!isSimpleXMLRoot((Root)object)) {
          throw marshalException;
        }
      }
    }
  }
 else {
    Class objectClass=object.getClass();
    if (object instanceof Collection) {
      try {
        writerRecord.startCollection();
        for (        Object o : (Collection)object) {
          marshal(o,writerRecord);
        }
        writerRecord.endCollection();
        writer.flush();
      }
 catch (      IOException e) {
        throw XMLMarshalException.marshalException(e);
      }
      return;
    }
 else     if (objectClass.isArray()) {
      try {
        writerRecord.startCollection();
        int arrayLength=Array.getLength(object);
        for (int x=0; x < arrayLength; x++) {
          marshal(Array.get(object,x),writerRecord);
        }
        writerRecord.endCollection();
        writer.flush();
      }
 catch (      IOException e) {
        throw XMLMarshalException.marshalException(e);
      }
      return;
    }
    if (session == null || xmlDescriptor == null) {
      session=context.getSession(objectClass);
      xmlDescriptor=getDescriptor(objectClass,session);
    }
  }
  marshal(object,writerRecord,session,xmlDescriptor,isXMLRoot);
  try {
    writer.flush();
  }
 catch (  IOException e) {
    throw XMLMarshalException.marshalException(e);
  }
}

Fixed version (ground truth):
private void marshal(Object object,Writer writer,ABSTRACT_SESSION session,DESCRIPTOR xmlDescriptor) throws XMLMarshalException {
  if ((object == null) || (writer == null)) {
    throw XMLMarshalException.nullArgumentException();
  }
  boolean isXMLRoot=false;
  String version=DEFAULT_XML_VERSION;
  String encoding=getEncoding();
  String callbackName=null;
  if (object instanceof JSONWithPadding) {
    callbackName=((JSONWithPadding)object).getCallbackName();
    object=((JSONWithPadding)object).getObject();
    if (object == null) {
      throw XMLMarshalException.nullArgumentException();
    }
  }
  if (object instanceof Root) {
    isXMLRoot=true;
    Root xroot=(Root)object;
    version=xroot.getXMLVersion() != null ? xroot.getXMLVersion() : version;
    encoding=xroot.getEncoding() != null ? xroot.getEncoding() : encoding;
  }
  MarshalRecord marshalRecord;
  writer=wrapWriter(writer);
  if (isFormattedOutput()) {
    if (isApplicationJSON()) {
      marshalRecord=new JSONFormattedWriterRecord(writer,callbackName);
    }
 else {
      marshalRecord=new FormattedWriterRecord();
      ((FormattedWriterRecord)marshalRecord).setWriter(writer);
    }
  }
 else {
    if (isApplicationJSON()) {
      marshalRecord=new JSONWriterRecord(writer,callbackName);
    }
 else {
      marshalRecord=new WriterRecord();
      ((WriterRecord)marshalRecord).setWriter(writer);
    }
  }
  marshalStreamOrWriter(object,marshalRecord,session,xmlDescriptor,isXMLRoot);
}