@Override
  public long position() throws IOException {
    checkOpen();

    long pos;

    synchronized (this) {
      boolean completed = false;
      try {
        begin(); // don't call beginBlocking() because this method doesn't block
        if (!isOpen()) {
          return 0; // AsynchronousCloseException will be thrown
        }
        pos = this.position;
        completed = true;
      } finally {
        end(completed);
      }
    }

    return pos;
  }
@Test
  public void testPositionNegative() throws IOException {
    FileChannel channel = channel(regularFile(0), READ, WRITE);

    try {
      channel.position(-1);
      fail();
    } catch (IllegalArgumentException expected) {
    }
  }