Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5019594

(ch spec) Fencepost error in scatter/gather interfaces

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs
    • generic
    • generic

      In the arguments for java.nio.ScatteringByteChannel/GatheringByteChannel,
      there is a section in the offset:

      ---begin---
      long read(ByteBuffer[] dsts,
                int offset,
                int length)

          offset - The offset within the buffer array of the first buffer
      into which bytes are to be transferred; must be non-negative and no
      larger than dsts.length
          length - The maximum number of buffers to be accessed; must be
      non-negative and no larger than dsts.length - offset
      ---end---

      Let's ignore the length parameter for a second. Shouldn't offset be
      restricted to point to something that actually exists? If
      array.length = 4, do you really want to try to read from array[4]?
      This seems to be allowed by the spec. I read the spec's wording as
      0 <= offset <= array.length.

      I believe the offset description should read "dst.length - 1".

      This exists in both Scatter and Gather.

      ###@###.### 2004-03-24

            sjiang Shanliang Jiang (Inactive)
            wetmore Bradford Wetmore
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: