code: static void checkBlockRange(List<LocatedBlock> blockRange,
        long offset, long length) throws IOException {
      boolean isValid = false;
  
      if (!blockRange.isEmpty()) {
        int numBlocks = blockRange.size();
        LocatedBlock firstBlock = blockRange.get(0);
        LocatedBlock lastBlock = blockRange.get(numBlocks - 1);
        long segmentEnd = offset + length;
  
        // Check that the queried segment is between the beginning of the first
        // block and the end of the last block in the block range.
        if (firstBlock.getStartOffset() <= offset &&
            (segmentEnd <=
             lastBlock.getStartOffset() + lastBlock.getBlockSize())) {
          isValid = true;  // There is a chance the block list is valid
          LocatedBlock prevBlock = firstBlock;
          for (int i = 1; i < numBlocks; ++i) {
            // In this loop, prevBlock is always the block #(i - 1) and curBlock
            // is the block #i.
            long prevBlkEnd = prevBlock.getStartOffset() +
                prevBlock.getBlockSize();
            LocatedBlock curBlock = blockRange.get(i);
            long curBlkOffset = curBlock.getStartOffset();
            if (prevBlkEnd != curBlkOffset ||  // Blocks are not contiguous
                prevBlkEnd <= offset ||        // Previous block is redundant
                segmentEnd <= curBlkOffset) {  // Current block is redundant
              isValid = false;
              break;
            }
            prevBlock = curBlock;
          }
        }
      }
  
      if (!isValid) {
        throw new IOException("Got incorrect block range for " +
            "offset=" + offset + ", length=" + length + ": " +
            blockRange);
      }
    }
docs: Checks that the given block range covers the given file segment and
  consists of contiguous blocks. This function assumes that the length
  of the queried segment is non-zero, and a non-empty block list is
  expected.
  @param blockRange the set of blocks obtained for the given file segment
  @param offset the start offset of the file segment
  @param length the length of the file segment. Assumed to be positive.