Program: 47747
Project: 47747
Buggy source:
@Override public void writeShortUTF(final DataOutput out,final String str,final int beginIndex,final int endIndex,final byte[] buffer) throws IOException {
  final boolean isBufferObjectDataOutput=out instanceof BufferObjectDataOutput;
  final BufferObjectDataOutput bufferObjectDataOutput=isBufferObjectDataOutput ? (BufferObjectDataOutput)out : null;
  int i;
  int c;
  int bufferPos=0;
  int utfLength=0;
  int utfLengthLimit;
  int pos=0;
  if (isBufferObjectDataOutput) {
    utfLengthLimit=str.length() * 3;
    pos=bufferObjectDataOutput.position();
    bufferObjectDataOutput.writeShort(0);
    if (ASCII_AWARE) {
      bufferObjectDataOutput.writeBoolean(false);
    }
  }
 else {
    utfLength=calculateUtf8Length(str,beginIndex,endIndex);
    if (utfLength > 65535) {
      throw new UTFDataFormatException("String_Node_Str" + utfLength + "String_Node_Str");
    }
    utfLengthLimit=utfLength;
    out.writeShort(utfLength);
    if (ASCII_AWARE) {
      out.writeBoolean(false);
    }
  }
  if (buffer.length >= utfLengthLimit) {
    for (i=beginIndex; i < endIndex; i++) {
      c=str.charAt(i);
      if (!((c <= 0x007F) && (c >= 0x0001))) {
        break;
      }
      buffer[bufferPos++]=(byte)c;
    }
    for (; i < endIndex; i++) {
      c=str.charAt(i);
      if (c <= 0) {
        buffer[bufferPos++]=(byte)(0xC0 | ((c >> 6) & 0x1F));
        buffer[bufferPos++]=(byte)(0x80 | ((c) & 0x3F));
      }
 else       if (c > 0x007F) {
        buffer[bufferPos++]=(byte)(0xE0 | ((c >> 12) & 0x0F));
        buffer[bufferPos++]=(byte)(0x80 | ((c >> 6) & 0x3F));
        buffer[bufferPos++]=(byte)(0x80 | ((c) & 0x3F));
      }
 else {
        buffer[bufferPos++]=(byte)c;
      }
    }
    out.write(buffer,0,bufferPos);
    if (isBufferObjectDataOutput) {
      utfLength=bufferPos;
    }
  }
 else {
    for (i=beginIndex; i < endIndex; i++) {
      c=str.charAt(i);
      if (!((c <= 0x007F) && (c >= 0x0001))) {
        break;
      }
      bufferPos=buffering(buffer,bufferPos,(byte)c,out);
    }
    if (isBufferObjectDataOutput) {
      utfLength=i - beginIndex;
    }
    for (; i < endIndex; i++) {
      c=str.charAt(i);
      if (c <= 0) {
        bufferPos=buffering(buffer,bufferPos,(byte)(0xC0 | ((c >> 6) & 0x1F)),out);
        bufferPos=buffering(buffer,bufferPos,(byte)(0x80 | ((c) & 0x3F)),out);
        if (isBufferObjectDataOutput) {
          utfLength+=2;
        }
      }
 else       if (c > 0x007F) {
        bufferPos=buffering(buffer,bufferPos,(byte)(0xE0 | ((c >> 12) & 0x0F)),out);
        bufferPos=buffering(buffer,bufferPos,(byte)(0x80 | ((c >> 6) & 0x3F)),out);
        bufferPos=buffering(buffer,bufferPos,(byte)(0x80 | ((c) & 0x3F)),out);
        if (isBufferObjectDataOutput) {
          utfLength+=3;
        }
      }
 else {
        bufferPos=buffering(buffer,bufferPos,(byte)c,out);
        if (isBufferObjectDataOutput) {
          utfLength++;
        }
      }
    }
    int length=bufferPos % buffer.length;
    out.write(buffer,0,length == 0 ? buffer.length : length);
  }
  if (isBufferObjectDataOutput) {
    if (utfLength > 65535) {
      throw new UTFDataFormatException("String_Node_Str" + utfLength + "String_Node_Str");
    }
    bufferObjectDataOutput.writeShort(pos,utfLength);
    if (ASCII_AWARE) {
      bufferObjectDataOutput.writeBoolean(pos + 2,utfLength == str.length());
    }
  }
}

Fixed version (ground truth):
@Override public void writeShortUTF(final DataOutput out,final String str,final int beginIndex,final int endIndex,final byte[] buffer) throws IOException {
  final boolean isBufferObjectDataOutput=out instanceof BufferObjectDataOutput;
  final BufferObjectDataOutput bufferObjectDataOutput=isBufferObjectDataOutput ? (BufferObjectDataOutput)out : null;
  int i;
  int c;
  int bufferPos=0;
  int utfLength=0;
  int utfLengthLimit;
  int pos=0;
  if (isBufferObjectDataOutput) {
    utfLengthLimit=str.length() * 3;
    pos=bufferObjectDataOutput.position();
    bufferObjectDataOutput.writeShort(0);
    if (ASCII_AWARE) {
      bufferObjectDataOutput.writeBoolean(false);
    }
  }
 else {
    utfLength=calculateUtf8Length(str,beginIndex,endIndex);
    if (utfLength > 65535) {
      throw new UTFDataFormatException("String_Node_Str" + utfLength + "String_Node_Str");
    }
    utfLengthLimit=utfLength;
    out.writeShort(utfLength);
    if (ASCII_AWARE) {
      out.writeBoolean(false);
    }
  }
  if (buffer.length >= utfLengthLimit) {
    for (i=beginIndex; i < endIndex; i++) {
      c=str.charAt(i);
      if (!(c <= 0x007F && c >= 0x0001)) {
        break;
      }
      buffer[bufferPos++]=(byte)c;
    }
    for (; i < endIndex; i++) {
      c=str.charAt(i);
      if ((c >= 0x0001) && (c <= 0x007F)) {
        buffer[bufferPos++]=(byte)c;
      }
 else       if (c > 0x07FF) {
        buffer[bufferPos++]=(byte)(0xE0 | ((c >> 12) & 0x0F));
        buffer[bufferPos++]=(byte)(0x80 | ((c >> 6) & 0x3F));
        buffer[bufferPos++]=(byte)(0x80 | ((c) & 0x3F));
      }
 else {
        buffer[bufferPos++]=(byte)(0xC0 | ((c >> 6) & 0x1F));
        buffer[bufferPos++]=(byte)(0x80 | ((c) & 0x3F));
      }
    }
    out.write(buffer,0,bufferPos);
    if (isBufferObjectDataOutput) {
      utfLength=bufferPos;
    }
  }
 else {
    for (i=beginIndex; i < endIndex; i++) {
      c=str.charAt(i);
      if (!(c <= 0x007F && c >= 0x0001)) {
        break;
      }
      bufferPos=buffering(buffer,bufferPos,(byte)c,out);
    }
    if (isBufferObjectDataOutput) {
      utfLength=i - beginIndex;
    }
    for (; i < endIndex; i++) {
      c=str.charAt(i);
      if (c <= 0x007F && c >= 0x0001) {
        bufferPos=buffering(buffer,bufferPos,(byte)c,out);
        if (isBufferObjectDataOutput) {
          utfLength++;
        }
      }
 else       if (c > 0x07FF) {
        bufferPos=buffering(buffer,bufferPos,(byte)(0xE0 | ((c >> 12) & 0x0F)),out);
        bufferPos=buffering(buffer,bufferPos,(byte)(0x80 | ((c >> 6) & 0x3F)),out);
        bufferPos=buffering(buffer,bufferPos,(byte)(0x80 | ((c) & 0x3F)),out);
        if (isBufferObjectDataOutput) {
          utfLength+=3;
        }
      }
 else {
        bufferPos=buffering(buffer,bufferPos,(byte)(0xC0 | ((c >> 6) & 0x1F)),out);
        bufferPos=buffering(buffer,bufferPos,(byte)(0x80 | ((c) & 0x3F)),out);
        if (isBufferObjectDataOutput) {
          utfLength+=2;
        }
      }
    }
    int length=bufferPos % buffer.length;
    out.write(buffer,0,length == 0 ? buffer.length : length);
  }
  if (isBufferObjectDataOutput) {
    if (utfLength > 65535) {
      throw new UTFDataFormatException("String_Node_Str" + utfLength + "String_Node_Str");
    }
    bufferObjectDataOutput.writeShort(pos,utfLength);
    if (ASCII_AWARE) {
      bufferObjectDataOutput.writeBoolean(pos + 2,utfLength == str.length());
    }
  }
}