Program: 132485
Project: 132485
Buggy source:
public Iterator<Entry<byte[],byte[]>> rangeLookup(final byte[] from,final byte[] to){
  final BlockReader itBlockIndex=blockIndex.clone();
  mappedFile.position(0);
  final ByteBuffer map=mappedFile.slice();
  final int blockIndexStart=from == null ? 0 : getBlockIndexPosition(from,itBlockIndex);
  final int blockIndexEnd=to == null ? itBlockIndex.getNumEntries() - 1 : getBlockIndexPosition(to,itBlockIndex);
  return new Iterator<Entry<byte[],byte[]>>(){
    private int currentBlockIndex;
    private Iterator<Entry<ByteRange,ByteRange>> currentBlockIterator;
    private BlockReader currentBlock;
{
      currentBlockIndex=blockIndexStart;
      getNextBlockData();
    }
    @Override public boolean hasNext(){
      while (currentBlockIterator != null) {
        if (currentBlockIterator.hasNext())         return true;
        currentBlockIndex++;
        getNextBlockData();
      }
      return false;
    }
    @Override public Entry<byte[],byte[]> next(){
      if (!hasNext())       throw new NoSuchElementException();
      final Entry<ByteRange,ByteRange> entry=currentBlockIterator.next();
      return new Entry<byte[],byte[]>(){
        private byte[] key;
        private byte[] value;
{
          key=entry.getKey().toBuffer();
          value=entry.getValue().toBuffer();
        }
        @Override public byte[] getKey(){
          return key;
        }
        @Override public byte[] getValue(){
          return value;
        }
        @Override public byte[] setValue(        byte[] value){
          throw new UnsupportedOperationException();
        }
      }
;
    }
    @Override public void remove(){
      throw new UnsupportedOperationException();
    }
    private void getNextBlockData(){
      if (blockIndexStart == -1 && blockIndexEnd == -1)       return;
      if (currentBlockIndex > blockIndexEnd) {
        currentBlock=null;
        currentBlockIterator=null;
        return;
      }
      int startOffset=getBlockOffset(currentBlockIndex,itBlockIndex);
      int endOffset=currentBlockIndex == itBlockIndex.getNumEntries() - 1 ? blockIndexOffset : getBlockOffset(currentBlockIndex + 1,itBlockIndex);
      currentBlock=getBlock(startOffset,endOffset,map);
      currentBlockIterator=currentBlock == null ? null : currentBlock.rangeLookup(from == null ? null : from,to == null ? null : to);
    }
  }
;
}

Fixed version (ground truth):
public Iterator<Entry<byte[],byte[]>> rangeLookup(final byte[] from,final byte[] to){
  final BlockReader itBlockIndex=blockIndex.clone();
  mappedFile.position(0);
  final ByteBuffer map=mappedFile.slice();
  int tmp=from == null ? 0 : getBlockIndexPosition(from,itBlockIndex);
  if (tmp < 0)   tmp=0;
  final int blockIndexStart=tmp;
  tmp=to == null ? itBlockIndex.getNumEntries() - 1 : getBlockIndexPosition(to,itBlockIndex);
  if (tmp > itBlockIndex.getNumEntries() - 1)   tmp=itBlockIndex.getNumEntries() - 1;
  final int blockIndexEnd=tmp;
  return new Iterator<Entry<byte[],byte[]>>(){
    private int currentBlockIndex;
    private Iterator<Entry<ByteRange,ByteRange>> currentBlockIterator;
    private BlockReader currentBlock;
{
      currentBlockIndex=blockIndexStart;
      getNextBlockData();
    }
    @Override public boolean hasNext(){
      while (currentBlockIterator != null) {
        if (currentBlockIterator.hasNext())         return true;
        currentBlockIndex++;
        getNextBlockData();
      }
      return false;
    }
    @Override public Entry<byte[],byte[]> next(){
      if (!hasNext())       throw new NoSuchElementException();
      final Entry<ByteRange,ByteRange> entry=currentBlockIterator.next();
      return new Entry<byte[],byte[]>(){
        private byte[] key;
        private byte[] value;
{
          key=entry.getKey().toBuffer();
          value=entry.getValue().toBuffer();
        }
        @Override public byte[] getKey(){
          return key;
        }
        @Override public byte[] getValue(){
          return value;
        }
        @Override public byte[] setValue(        byte[] value){
          throw new UnsupportedOperationException();
        }
      }
;
    }
    @Override public void remove(){
      throw new UnsupportedOperationException();
    }
    private void getNextBlockData(){
      if (blockIndexStart == -1 && blockIndexEnd == -1)       return;
      if (currentBlockIndex > blockIndexEnd) {
        currentBlock=null;
        currentBlockIterator=null;
        return;
      }
      int startOffset=getBlockOffset(currentBlockIndex,itBlockIndex);
      int endOffset=currentBlockIndex == itBlockIndex.getNumEntries() - 1 ? blockIndexOffset : getBlockOffset(currentBlockIndex + 1,itBlockIndex);
      currentBlock=getBlock(startOffset,endOffset,map);
      currentBlockIterator=currentBlock == null ? null : currentBlock.rangeLookup(from == null ? null : from,to == null ? null : to);
    }
  }
;
}