Program: 33388
Project: 33388
Buggy source:
/** 
 * Packs all or part of the input byte array which uses "bits" bits to use all 8 bits. <p> We assume len is a multiplication of stride. The parameter stride controls the packing unit length and different units <b>DO NOT</b> share same byte. This happens when packing image data where each scan line <b>MUST</b> start at byte boundary like TIFF.
 * @param input input byte array to be packed
 * @param stride length of packing unit
 * @param start offset of the input array to start packing  
 * @param bits number of bits used in each byte of the input
 * @param len number of input bytes to be packed
 * @return the packed byte array
 */
public static byte[] packByteArray(byte[] input,int stride,int start,int bits,int len){
  if (bits == 8)   return ArrayUtils.subArray(input,start,len);
  if (bits > 8 || bits <= 0)   throw new IllegalArgumentException("String_Node_Str" + bits);
  int bitsPerStride=bits * stride;
  int numOfStrides=len / stride;
  byte[] packedBytes=new byte[((bitsPerStride + 7) >> 3) * numOfStrides];
  short mask[]={0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};
  int index=0;
  int empty_bits=8;
  int end=start + len;
  int strideCounter=0;
  for (int i=start; i < end; i++, strideCounter++) {
    if (empty_bits >= bits) {
      packedBytes[index]|=((input[i] & mask[bits]) << (empty_bits - bits));
      empty_bits-=bits;
    }
 else {
      packedBytes[index++]|=((input[i] >> (bits - empty_bits)) & mask[empty_bits]);
      packedBytes[index]|=((input[i] & mask[bits - empty_bits]) << (8 - bits + empty_bits));
      empty_bits+=(8 - bits);
    }
    if (++strideCounter % stride == 0 || empty_bits == 0) {
      index++;
      empty_bits=8;
    }
  }
  return packedBytes;
}

Fixed version (ground truth):
/** 
 * Packs all or part of the input byte array which uses "bits" bits to use all 8 bits. <p> We assume len is a multiplication of stride. The parameter stride controls the packing unit length and different units <b>DO NOT</b> share same byte. This happens when packing image data where each scan line <b>MUST</b> start at byte boundary like TIFF.
 * @param input input byte array to be packed
 * @param stride length of packing unit
 * @param start offset of the input array to start packing  
 * @param bits number of bits used in each byte of the input
 * @param len number of input bytes to be packed
 * @return the packed byte array
 */
public static byte[] packByteArray(byte[] input,int stride,int start,int bits,int len){
  if (bits == 8)   return ArrayUtils.subArray(input,start,len);
  if (bits > 8 || bits <= 0)   throw new IllegalArgumentException("String_Node_Str" + bits);
  int bitsPerStride=bits * stride;
  int numOfStrides=len / stride;
  byte[] packedBytes=new byte[((bitsPerStride + 7) >> 3) * numOfStrides];
  short mask[]={0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};
  int index=0;
  int empty_bits=8;
  int end=start + len;
  int strideCounter=0;
  for (int i=start; i < end; i++) {
    if (empty_bits >= bits) {
      packedBytes[index]|=((input[i] & mask[bits]) << (empty_bits - bits));
      empty_bits-=bits;
    }
 else {
      packedBytes[index++]|=((input[i] >> (bits - empty_bits)) & mask[empty_bits]);
      packedBytes[index]|=((input[i] & mask[bits - empty_bits]) << (8 - bits + empty_bits));
      empty_bits+=(8 - bits);
    }
    if (++strideCounter % stride == 0 || empty_bits == 0) {
      index++;
      empty_bits=8;
    }
  }
  return packedBytes;
}