Program: 100997
Project: 100997
Buggy source:
public BytesSuccinctBitVector(byte[] bytes,int bitsSize){
  this.bytes=Arrays.copyOf(bytes,containerBytesCount(bitsSize));
  this.size=bitsSize;
  int cacheSize=bitsSize / CACHE_WIDTH + 1;
  countCache0=new int[cacheSize + 1];
  indexCache0=new int[cacheSize + 1];
  int n=bytes.length;
  for (int i=0; i < n; i++) {
    int b=bytes[i] & 0xff;
    byte[] zeroPosInB=BITPOS0[b];
    int rest=bitsSize - i * 8;
    if (rest < 8) {
      int nz=zeroPosInB.length;
      for (int j=0; j < nz; j++) {
        if (zeroPosInB[j] >= rest) {
          zeroPosInB=Arrays.copyOf(zeroPosInB,j);
          break;
        }
      }
    }
    int zeroCount=zeroPosInB.length;
    if (size0 < 3 && zeroCount > 0) {
      if (size0 == 0) {
        node1pos=zeroPosInB[0] + 8 * i;
        if (zeroPosInB.length > 1)         node2pos=zeroPosInB[1] + 8 * i;
        if (zeroPosInB.length > 2)         node3pos=zeroPosInB[2] + 8 * i;
      }
 else       if (size0 == 1) {
        node2pos=zeroPosInB[0] + 8 * i;
        if (zeroPosInB.length > 1)         node3pos=zeroPosInB[1] + 8 * i;
      }
 else {
        node3pos=zeroPosInB[0] + 8 * i;
      }
    }
    int prevSize0=size0;
    size0+=zeroCount;
    if ((i + 1) % (CACHE_WIDTH / 8) == 0) {
      countCache0[i / (CACHE_WIDTH / 8)]=size0;
    }
    if (zeroCount > 0 && ((size0 / CACHE_WIDTH) != (prevSize0 / CACHE_WIDTH))) {
      indexCache0[size0 / CACHE_WIDTH]=prevSize0 + zeroPosInB[zeroPosInB.length - size0 % CACHE_WIDTH - 1];
    }
    if (rest < 8)     break;
  }
  countCache0[(size - 1) / CACHE_WIDTH]=size0;
  if (indexCache0[size0 / CACHE_WIDTH] == 0) {
    indexCache0[size0 / CACHE_WIDTH]=size;
  }
 else {
    indexCache0[(size0 / CACHE_WIDTH) + 1]=size;
  }
}

Fixed version (ground truth):
public BytesSuccinctBitVector(byte[] bytes,int bitsSize){
  this.bytes=Arrays.copyOf(bytes,containerBytesCount(bitsSize));
  this.size=bitsSize;
  int cacheSize=bitsSize / CACHE_WIDTH + 1;
  countCache0=new int[cacheSize + 1];
  indexCache0=new int[cacheSize / 2 + 1];
  int n=bytes.length;
  for (int i=0; i < n; i++) {
    int b=bytes[i] & 0xff;
    byte[] zeroPosInB=BITPOS0[b];
    int rest=bitsSize - i * 8;
    if (rest < 8) {
      int nz=zeroPosInB.length;
      for (int j=0; j < nz; j++) {
        if (zeroPosInB[j] >= rest) {
          zeroPosInB=Arrays.copyOf(zeroPosInB,j);
          break;
        }
      }
    }
    int zeroCount=zeroPosInB.length;
    if (size0 < 3 && zeroCount > 0) {
      if (size0 == 0) {
        node1pos=zeroPosInB[0] + 8 * i;
        if (zeroPosInB.length > 1)         node2pos=zeroPosInB[1] + 8 * i;
        if (zeroPosInB.length > 2)         node3pos=zeroPosInB[2] + 8 * i;
      }
 else       if (size0 == 1) {
        node2pos=zeroPosInB[0] + 8 * i;
        if (zeroPosInB.length > 1)         node3pos=zeroPosInB[1] + 8 * i;
      }
 else {
        node3pos=zeroPosInB[0] + 8 * i;
      }
    }
    int prevSize0=size0;
    size0+=zeroCount;
    if ((i + 1) % (CACHE_WIDTH / 8) == 0) {
      countCache0[i / (CACHE_WIDTH / 8)]=size0;
    }
    if (zeroCount > 0 && ((size0 / CACHE_WIDTH) != (prevSize0 / CACHE_WIDTH))) {
      indexCache0[size0 / CACHE_WIDTH]=i * 8 + zeroPosInB[zeroPosInB.length - (size0 % CACHE_WIDTH) - 1];
    }
    if (rest < 8)     break;
  }
  countCache0[(size - 1) / CACHE_WIDTH]=size0;
}