Program: 65393
Project: 65393
Buggy source:
/** 
 * INTERNAL:
 */
protected void writeValue(String value,boolean escapeChars,boolean isAttribute){
  if (escapeChars) {
    CharacterEscapeHandler escapeHandler=marshaller.getCharacterEscapeHandler();
    if (escapeHandler != null) {
      try {
        CharArrayWriter out=new CharArrayWriter();
        escapeHandler.escape(value.toCharArray(),0,value.length(),isAttribute,out);
        byte[] bytes=out.toString().getBytes();
        outputStreamWrite(bytes);
        out.close();
      }
 catch (      IOException e) {
        throw XMLMarshalException.marshalException(e);
      }
      return;
    }
  }
  for (int x=0, length=value.length(); x < length; x++) {
    final char character=value.charAt(x);
    if (character > 0x7F) {
      if (character > 0x7FF) {
        if ((character >= Character.MIN_HIGH_SURROGATE) && (character <= Character.MAX_LOW_SURROGATE)) {
          int uc=(((character & 0x3ff) << 10) | (value.charAt(++x) & 0x3ff)) + 0x10000;
          outputStreamWrite((byte)(0xF0 | ((uc >> 18))));
          outputStreamWrite((byte)(0x80 | ((uc >> 12) & 0x3F)));
          outputStreamWrite((byte)(0x80 | ((uc >> 6) & 0x3F)));
          outputStreamWrite((byte)(0x80 + (uc & 0x3F)));
          continue;
        }
 else {
          outputStreamWrite((byte)(0xE0 + (character >> 12)));
        }
        outputStreamWrite((byte)(0x80 + ((character >> 6) & 0x3F)));
      }
 else {
        outputStreamWrite((byte)(0xC0 + (character >> 6)));
      }
      outputStreamWrite((byte)(0x80 + (character & 0x3F)));
    }
 else {
      if (escapeChars) {
switch (character) {
case '&':
{
            outputStreamWrite(AMP);
            break;
          }
case '<':
{
          outputStreamWrite(LT);
          break;
        }
case '"':
{
        outputStreamWrite(QUOT);
        break;
      }
default :
    outputStreamWrite((byte)character);
}
}
 else {
outputStreamWrite((byte)character);
}
}
}
}

Fixed version (ground truth):
/** 
 * INTERNAL:
 */
protected void writeValue(String value,boolean escapeChars,boolean isAttribute,OutputStream os){
  if (escapeChars) {
    CharacterEscapeHandler escapeHandler=marshaller.getCharacterEscapeHandler();
    if (escapeHandler != null) {
      try {
        CharArrayWriter out=new CharArrayWriter();
        escapeHandler.escape(value.toCharArray(),0,value.length(),isAttribute,out);
        byte[] bytes=out.toString().getBytes();
        outputStreamWrite(bytes);
        out.close();
      }
 catch (      IOException e) {
        throw XMLMarshalException.marshalException(e);
      }
      return;
    }
  }
  for (int x=0, length=value.length(); x < length; x++) {
    final char character=value.charAt(x);
    if (character > 0x7F) {
      if (character > 0x7FF) {
        if ((character >= Character.MIN_HIGH_SURROGATE) && (character <= Character.MAX_LOW_SURROGATE)) {
          int uc=(((character & 0x3ff) << 10) | (value.charAt(++x) & 0x3ff)) + 0x10000;
          outputStreamWrite((byte)(0xF0 | ((uc >> 18))),os);
          outputStreamWrite((byte)(0x80 | ((uc >> 12) & 0x3F)),os);
          outputStreamWrite((byte)(0x80 | ((uc >> 6) & 0x3F)),os);
          outputStreamWrite((byte)(0x80 + (uc & 0x3F)),os);
          continue;
        }
 else {
          outputStreamWrite((byte)(0xE0 + (character >> 12)),os);
        }
        outputStreamWrite((byte)(0x80 + ((character >> 6) & 0x3F)),os);
      }
 else {
        outputStreamWrite((byte)(0xC0 + (character >> 6)),os);
      }
      outputStreamWrite((byte)(0x80 + (character & 0x3F)),os);
    }
 else {
      if (escapeChars) {
switch (character) {
case '&':
{
            outputStreamWrite(AMP,os);
            break;
          }
case '<':
{
          outputStreamWrite(LT,os);
          break;
        }
case '"':
{
        outputStreamWrite(QUOT,os);
        break;
      }
default :
    outputStreamWrite((byte)character,os);
}
}
 else {
outputStreamWrite((byte)character,os);
}
}
}
}