code: protected void checkOffset(long offset) {
      if (offset(offset) < this.offset) {
        throw new IndexOutOfBoundsException();
      } else if (limit == -1) {
        if (offset > maxCapacity)
          throw new IndexOutOfBoundsException();
      } else {
        if (offset > limit)
          throw new IndexOutOfBoundsException();
      }
    }
docs: Checks that the offset is within the bounds of the buffer.