You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by "Justin SB (JIRA)" <ji...@apache.org> on 2013/12/17 00:10:06 UTC

[jira] [Created] (ZOOKEEPER-1843) Oddity in ByteBufferInputStream skip

Justin SB created ZOOKEEPER-1843:
------------------------------------

             Summary: Oddity in ByteBufferInputStream skip
                 Key: ZOOKEEPER-1843
                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1843
             Project: ZooKeeper
          Issue Type: Bug
            Reporter: Justin SB
            Priority: Minor


I was reading ByteBufferInputStream.java; here is the skip method:

    public long skip(long n) throws IOException {
        long newPos = bb.position() + n;
        if (newPos > bb.remaining()) {
            n = bb.remaining();
        }
        bb.position(bb.position() + (int) n);
        return n;
    }

The first two lines look wrong; we compare a "point" (position) to a "distance" (remaining).  I think the test should be if (newPos >= bb.limit()).

Or more simply:
    public long skip(long n) throws IOException {
        int remaining = buffer.remaining();
        if (n > remaining) {
            n = remaining;
        }
        buffer.position(buffer.position() + (int) n);
        return n;
    }




--
This message was sent by Atlassian JIRA
(v6.1.4#6159)