Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-1843

Oddity in ByteBufferInputStream skip

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 3.5.0
    • None
    • None

    Description

      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;
      }

      Attachments

        1. ZOOKEEPER-1843.v2.patch
          6 kB
          Bill Havanki
        2. ZOOKEEPER-1843.patch
          5 kB
          Bill Havanki

        Activity

          People

            bhavanki Bill Havanki
            justinsb Justin SB
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: