Program: 135832
Project: 135832
Buggy source:
/** 
 * It aligns the last numBits bits to the head of the byte array following them with numBits % 8 zero bits. <p/> Example: For inputbytes = [00000111][01110001] and numBits = 12 it returns: shiftedBytes = [01110111][00010000]
 * @param byte[] inputBytes
 * @param int    numBits - number of bits to be left aligned
 * @return byte[]
 */
public static byte[] shiftBitsToMSB(byte[] inputBytes,int numBits){
  int numBitstoShiftBy=0, leadZeroesMSB=8, numEndRestBits=0;
  int size=inputBytes.length;
  byte[] shiftedBytes=new byte[size];
  int i;
  for (i=0; i < Byte.SIZE; i++) {
    if (((byte)(inputBytes[0] & getMSBMask(i + 1))) != 0) {
      leadZeroesMSB=i;
      break;
    }
  }
  if (numBits % NetUtils.NumBitsInAByte == 0) {
    numBitstoShiftBy=0;
  }
 else {
    numBitstoShiftBy=((NetUtils.NumBitsInAByte - (numBits % NetUtils.NumBitsInAByte)) < leadZeroesMSB) ? (NetUtils.NumBitsInAByte - (numBits % NetUtils.NumBitsInAByte)) : leadZeroesMSB;
  }
  if (numBitstoShiftBy == 0) {
    return inputBytes;
  }
  if (numBits < NetUtils.NumBitsInAByte) {
    shiftedBytes[0]=(byte)((inputBytes[0] & getLSBMask(numBits)) << numBitstoShiftBy);
  }
 else {
    numEndRestBits=NetUtils.NumBitsInAByte - (inputBytes.length * NetUtils.NumBitsInAByte - numBits - numBitstoShiftBy);
    for (i=0; i < (size - 1); i++) {
      if ((i + 1) == (size - 1)) {
        if (numEndRestBits > numBitstoShiftBy) {
          shiftedBytes[i]=(byte)((inputBytes[i] << numBitstoShiftBy) | ((inputBytes[i + 1] & getMSBMask(numBitstoShiftBy)) >> (numEndRestBits - numBitstoShiftBy)));
          shiftedBytes[i + 1]=(byte)((inputBytes[i + 1] & getLSBMask(numEndRestBits - numBitstoShiftBy)) << numBitstoShiftBy);
        }
 else         shiftedBytes[i]=(byte)((inputBytes[i] << numBitstoShiftBy) | ((inputBytes[i + 1] & getMSBMask(numEndRestBits)) >> (NetUtils.NumBitsInAByte - numEndRestBits)));
      }
      shiftedBytes[i]=(byte)((inputBytes[i] << numBitstoShiftBy) | (inputBytes[i + 1] & getMSBMask(numBitstoShiftBy)) >> (NetUtils.NumBitsInAByte - numBitstoShiftBy));
    }
  }
  return shiftedBytes;
}

Fixed version (ground truth):
/** 
 * It aligns the last numBits bits to the head of the byte array following them with numBits % 8 zero bits. <p> Example: For inputbytes = [00000111][01110001] and numBits = 12 it returns: shiftedBytes = [01110111][00010000]
 * @param inputBytes
 * @param numBits number of bits to be left aligned
 * @return byte[]
 */
public static byte[] shiftBitsToMSB(byte[] inputBytes,int numBits){
  int numBitstoShiftBy=0, leadZeroesMSB=8, numEndRestBits=0;
  int size=inputBytes.length;
  byte[] shiftedBytes=new byte[size];
  int i;
  for (i=0; i < Byte.SIZE; i++) {
    if (((byte)(inputBytes[0] & getMSBMask(i + 1))) != 0) {
      leadZeroesMSB=i;
      break;
    }
  }
  if (numBits % NetUtils.NumBitsInAByte == 0) {
    numBitstoShiftBy=0;
  }
 else {
    numBitstoShiftBy=((NetUtils.NumBitsInAByte - (numBits % NetUtils.NumBitsInAByte)) < leadZeroesMSB) ? (NetUtils.NumBitsInAByte - (numBits % NetUtils.NumBitsInAByte)) : leadZeroesMSB;
  }
  if (numBitstoShiftBy == 0) {
    return inputBytes;
  }
  if (numBits < NetUtils.NumBitsInAByte) {
    shiftedBytes[0]=(byte)((inputBytes[0] & getLSBMask(numBits)) << numBitstoShiftBy);
  }
 else {
    numEndRestBits=NetUtils.NumBitsInAByte - (inputBytes.length * NetUtils.NumBitsInAByte - numBits - numBitstoShiftBy);
    for (i=0; i < (size - 1); i++) {
      if ((i + 1) == (size - 1)) {
        if (numEndRestBits > numBitstoShiftBy) {
          shiftedBytes[i]=(byte)((inputBytes[i] << numBitstoShiftBy) | ((inputBytes[i + 1] & getMSBMask(numBitstoShiftBy)) >> (numEndRestBits - numBitstoShiftBy)));
          shiftedBytes[i + 1]=(byte)((inputBytes[i + 1] & getLSBMask(numEndRestBits - numBitstoShiftBy)) << numBitstoShiftBy);
        }
 else         shiftedBytes[i]=(byte)((inputBytes[i] << numBitstoShiftBy) | ((inputBytes[i + 1] & getMSBMask(numEndRestBits)) >> (NetUtils.NumBitsInAByte - numEndRestBits)));
      }
      shiftedBytes[i]=(byte)((inputBytes[i] << numBitstoShiftBy) | (inputBytes[i + 1] & getMSBMask(numBitstoShiftBy)) >> (NetUtils.NumBitsInAByte - numBitstoShiftBy));
    }
  }
  return shiftedBytes;
}