Program: 156408
Project: 156408
Buggy source:
/** 
 * Writes a fixed number of bits out to the stream.
 * @param value the value to write out.
 * @param length The number of bits to write.
 * @return This buffer.
 * @throws IllegalArgumentException if the length argument was less than 1 or greater than 32. 
 */
public PacketBufferBC writeFixedBits(int value,int length) throws IllegalArgumentException {
  if (length <= 0) {
    throw new IllegalArgumentException("String_Node_Str" + length + "String_Node_Str");
  }
  if (length > 32) {
    throw new IllegalArgumentException("String_Node_Str" + length + "String_Node_Str");
  }
  writePartialBitsBegin();
  if (writePartialOffset > 0) {
    int availbleBits=8 - writePartialOffset;
    if (availbleBits >= length) {
      int mask=(1 << length) - 1;
      int bitsToWrite=value & mask;
      writePartialCache|=bitsToWrite << writePartialOffset;
      setByte(writePartialIndex,writePartialCache);
      writePartialOffset+=length;
      return this;
    }
 else {
      int mask=(1 << availbleBits) - 1;
      int shiftBack=length - availbleBits;
      int bitsToWrite=(value >>> shiftBack) & mask;
      writePartialCache|=bitsToWrite << writePartialOffset;
      setByte(writePartialIndex,writePartialCache);
      writePartialCache=0;
      writePartialOffset=8;
      value>>>=shiftBack;
      length-=shiftBack;
    }
  }
  while (length >= 8) {
    writePartialBitsBegin();
    int byteToWrite=(value >>> (length - 8)) & 0xFFFF;
    setByte(writePartialIndex,byteToWrite);
    writePartialCache=0;
    writePartialOffset=8;
    value>>>=8;
    length-=8;
  }
  if (length > 0) {
    writePartialBitsBegin();
    int mask=(1 << length) - 1;
    writePartialCache=value & mask;
    setByte(writePartialIndex,writePartialCache);
    writePartialOffset=length;
  }
  return this;
}

Fixed version (ground truth):
/** 
 * Writes a fixed number of bits out to the stream.
 * @param value the value to write out.
 * @param length The number of bits to write.
 * @return This buffer.
 * @throws IllegalArgumentException if the length argument was less than 1 or greater than 32. 
 */
public PacketBufferBC writeFixedBits(int value,int length) throws IllegalArgumentException {
  if (length <= 0) {
    throw new IllegalArgumentException("String_Node_Str" + length + "String_Node_Str");
  }
  if (length > 32) {
    throw new IllegalArgumentException("String_Node_Str" + length + "String_Node_Str");
  }
  writePartialBitsBegin();
  if (writePartialOffset > 0) {
    int availbleBits=8 - writePartialOffset;
    if (availbleBits >= length) {
      int mask=(1 << length) - 1;
      int bitsToWrite=value & mask;
      writePartialCache|=bitsToWrite << writePartialOffset;
      setByte(writePartialIndex,writePartialCache);
      writePartialOffset+=length;
      return this;
    }
 else {
      int mask=(1 << availbleBits) - 1;
      int shift=length - availbleBits;
      int bitsToWrite=(value >>> shift) & mask;
      writePartialCache|=bitsToWrite << writePartialOffset;
      setByte(writePartialIndex,writePartialCache);
      writePartialCache=0;
      writePartialOffset=8;
      length-=availbleBits;
    }
  }
  while (length >= 8) {
    writePartialBitsBegin();
    int byteToWrite=(value >>> (length - 8)) & 0xFF;
    setByte(writePartialIndex,byteToWrite);
    writePartialCache=0;
    writePartialOffset=8;
    length-=8;
  }
  if (length > 0) {
    writePartialBitsBegin();
    int mask=(1 << length) - 1;
    writePartialCache=value & mask;
    setByte(writePartialIndex,writePartialCache);
    writePartialOffset=length;
  }
  return this;
}