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

X-Buffer.compact: Fencepost error in specification

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • core-libs
    • beta
    • sparc
    • solaris_7
    • Verified

      Specification for CharBuffer.compact() says
      "..the character at index p = position() is copied to index zero, the character at index p + 1 is copied to index one, and so forth until the character at index limit() - 1 is copied to index n = limit() - p. The buffer's position is then set to n and its limit is set to its capacity..."

      Say we have :
      String s = "abcdefghij";
      CharBuffer c = CharBuffer.wrap(c.toCharArray());
      c.position(4);
      c.limit(7);

      Over here character at index 4 is "e" and character at index 7 is "h".
      therefore:
      c.compact();
      should copy :
      "e" to index 0
      "f" to index 1
      "g" to index 2

      since "h" is the first character where limit starts, therefore it wont be copied.

      Now index of g is 2 but according to the specs it should be limit()-p i.e.
      7-4 = 3. Which is not the case.


            mr Mark Reinhold
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: