Program: 44748
Project: 44748
Buggy source:
/** 
 * Remove the document at the specified position
 * @param bytes
 * @return
 */
public static byte[] delete(byte[] bytes,short docPos){
  if (null == bytes)   return null;
  int pos=0;
  int bytesT=bytes.length;
  if (0 == bytesT)   return null;
  Map<Integer,Integer> rowcol=new HashMap<Integer,Integer>();
  int row=0;
  int termsT=0;
  int col=-1;
  short dp;
  while (pos < bytesT) {
    row++;
    pos=pos + 4;
    termsT=(byte)bytes[pos++];
    if (-1 == termsT) {
      termsT=Storable.getInt(pos,bytes);
      pos=pos + 4;
    }
    pos=pos + (termsT * 3);
    if (TermList.termVectorStorageEnabled)     pos=pos + (termsT * 3);
    col=-2;
    for (int i=0; i < termsT; i++) {
      dp=Storable.getShort(pos,bytes);
      pos=pos + 2;
      if (dp == docPos) {
        col=(termsT == 1) ? -1 : i;
        break;
      }
    }
    if (-2 != col) {
      rowcol.put(row,col);
      pos=pos + (termsT - col - 1) * 2;
    }
  }
  pos=0;
  row=0;
  ByteBuffer bb=ByteBuffer.allocate(bytes.length);
  while (pos < bytesT) {
    row++;
    boolean cutRow=rowcol.containsKey(row);
    if (cutRow && rowcol.get(row) == -1) {
      pos=pos + 4;
      termsT=(byte)bytes[pos++];
      if (-1 == termsT)       termsT=Storable.getInt(pos,bytes);
      pos=pos + 4;
      if (TermList.termVectorStorageEnabled)       pos=pos + termsT * 8;
 else       pos=pos + termsT * 5;
      continue;
    }
    bb.put(bytes,pos,4);
    pos=pos + 4;
    termsT=(byte)bytes[pos++];
    if (-1 == termsT) {
      bb.put((byte)-1);
      termsT=Storable.getInt(pos,bytes);
      bb.put(bytes,pos,4);
      pos=pos + 4;
    }
 else {
      if (cutRow)       bb.put((byte)(termsT - 1));
 else       bb.put((byte)(termsT));
    }
    if (cutRow) {
      col=rowcol.get(row);
      if (col != 0)       bb.put(bytes,pos,col);
      bb.put(bytes,pos + col + 1,termsT - col - 1);
      pos=pos + termsT;
      if (col != 0)       bb.put(bytes,pos,col);
      bb.put(bytes,pos + col + 1,termsT - col - 1);
      pos=pos + termsT;
      if (col != 0)       bb.put(bytes,pos,col);
      bb.put(bytes,pos + col + 1,termsT - col - 1);
      pos=pos + termsT;
      if (TermList.termVectorStorageEnabled) {
        if (col != 0)         bb.put(bytes,pos,col);
        bb.put(bytes,pos + col + 1,termsT - col - 1);
        pos=pos + termsT;
        if (col != 0)         bb.put(bytes,pos,(col) * 2);
        bb.put(bytes,pos + (col + 1) * 2,(termsT - col - 1) * 2);
        pos=pos + termsT * 2;
      }
      if (col != 0)       bb.put(bytes,pos,col * 2);
      bb.put(bytes,pos + (col + 1) * 2,(termsT - col - 1) * 2);
      pos=pos + termsT * 2;
    }
 else {
      if (TermList.termVectorStorageEnabled) {
        bb.put(bytes,pos,termsT * 8);
        pos=pos + termsT * 8;
      }
 else {
        bb.put(bytes,pos,termsT * 5);
        pos=pos + termsT * 5;
      }
    }
  }
  int len=bb.position();
  if (0 == len)   return null;
  byte[] deletedB=new byte[len];
  bb.position(0);
  bb.get(deletedB,0,len);
  bb.clear();
  return deletedB;
}

Fixed version (ground truth):
/** 
 * Remove the document at the specified position
 * @param bytes
 * @return
 */
public static byte[] delete(byte[] bytes,short docPos){
  if (null == bytes)   return null;
  int pos=0;
  int bytesT=bytes.length;
  if (0 == bytesT)   return null;
  Map<Integer,Integer> rowcol=new HashMap<Integer,Integer>();
  int row=0;
  int termsT=0;
  int col=-1;
  short dp;
  while (pos < bytesT) {
    row++;
    pos=pos + 4;
    termsT=(byte)bytes[pos++];
    if (-1 == termsT) {
      termsT=Storable.getInt(pos,bytes);
      pos=pos + 4;
    }
    pos=pos + (termsT * 3);
    if (TermList.termVectorStorageEnabled)     pos=pos + (termsT * 3);
    col=Integer.MIN_VALUE;
    for (int i=0; i < termsT; i++) {
      dp=Storable.getShort(pos,bytes);
      pos=pos + 2;
      if (dp == docPos) {
        pos=pos + (termsT - i - 1) * 2;
        col=(termsT == 1) ? -1 : i;
        break;
      }
    }
    if (Integer.MIN_VALUE != col)     rowcol.put(row,col);
  }
  pos=0;
  row=0;
  ByteBuffer bb=ByteBuffer.allocate(bytes.length);
  while (pos < bytesT) {
    row++;
    boolean cutRow=rowcol.containsKey(row);
    if (cutRow && rowcol.get(row) == -1) {
      pos=pos + 4;
      termsT=(byte)bytes[pos++];
      if (-1 == termsT) {
        termsT=Storable.getInt(pos,bytes);
        pos=pos + 4;
      }
      if (TermList.termVectorStorageEnabled)       pos=pos + termsT * 8;
 else       pos=pos + termsT * 5;
      continue;
    }
    bb.put(bytes,pos,4);
    pos=pos + 4;
    termsT=(byte)bytes[pos++];
    if (-1 == termsT) {
      bb.put((byte)-1);
      termsT=Storable.getInt(pos,bytes);
      bb.put(bytes,pos,4);
      pos=pos + 4;
    }
 else {
      if (cutRow)       bb.put((byte)(termsT - 1));
 else       bb.put((byte)(termsT));
    }
    if (cutRow) {
      col=rowcol.get(row);
      if (col != 0)       bb.put(bytes,pos,col);
      bb.put(bytes,pos + col + 1,termsT - col - 1);
      pos=pos + termsT;
      if (col != 0)       bb.put(bytes,pos,col);
      bb.put(bytes,pos + col + 1,termsT - col - 1);
      pos=pos + termsT;
      if (col != 0)       bb.put(bytes,pos,col);
      bb.put(bytes,pos + col + 1,termsT - col - 1);
      pos=pos + termsT;
      if (TermList.termVectorStorageEnabled) {
        if (col != 0)         bb.put(bytes,pos,col);
        bb.put(bytes,pos + col + 1,termsT - col - 1);
        pos=pos + termsT;
        if (col != 0)         bb.put(bytes,pos,(col) * 2);
        bb.put(bytes,pos + (col + 1) * 2,(termsT - col - 1) * 2);
        pos=pos + termsT * 2;
      }
      if (col != 0)       bb.put(bytes,pos,col * 2);
      bb.put(bytes,pos + (col + 1) * 2,(termsT - col - 1) * 2);
      pos=pos + termsT * 2;
    }
 else {
      if (TermList.termVectorStorageEnabled) {
        bb.put(bytes,pos,termsT * 8);
        pos=pos + termsT * 8;
      }
 else {
        bb.put(bytes,pos,termsT * 5);
        pos=pos + termsT * 5;
      }
    }
  }
  int len=bb.position();
  if (0 == len)   return null;
  byte[] deletedB=new byte[len];
  bb.position(0);
  bb.get(deletedB,0,len);
  bb.clear();
  return deletedB;
}