Program: 63295
Project: 63295
Buggy source:
/** 
 * 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;
      }
case '\n':
{
      if (isAttribute) {
        outputStreamWrite(SLASH_N,os);
      }
 else {
        outputStreamWrite((byte)character,os);
      }
      break;
    }
case '\r':
{
    outputStreamWrite(SLASH_R,os);
    break;
  }
default :
outputStreamWrite((byte)character,os);
}
}
 else {
outputStreamWrite((byte)character,os);
}
}
}
}

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;
    }
  }
  int nClosingSquareBracketsInRow=0;
  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 '>':
{
        if (nClosingSquareBracketsInRow >= 2) {
          outputStreamWrite(GT,os);
        }
 else {
          outputStreamWrite((byte)character,os);
        }
        break;
      }
case '"':
{
      outputStreamWrite(QUOT,os);
      break;
    }
case '\n':
{
    if (isAttribute) {
      outputStreamWrite(SLASH_N,os);
    }
 else {
      outputStreamWrite((byte)character,os);
    }
    break;
  }
case '\r':
{
  outputStreamWrite(SLASH_R,os);
  break;
}
default :
outputStreamWrite((byte)character,os);
}
if (!isAttribute) {
if (']' == character) {
++nClosingSquareBracketsInRow;
}
 else {
nClosingSquareBracketsInRow=0;
}
}
}
 else {
outputStreamWrite((byte)character,os);
}
}
}
}