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

(spec) <view buffer>.capacity() returns type-specific size

XMLWordPrintable

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

      per ByteBuffer.asDoubleBuffer() spec:

      "The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer rounded down to the nearest multiple of eight .."

      However, capacity() returns number_of_bytes/8.

      -----------------------------
          public static void test() {

      int size = randomSize(); // randomSize() returns random int value
      DoubleBuffer d = ByteBuffer.allocate(size).asDoubleBuffer();

      int cap = d.capacity();
      int pos = d.position();
      int lim = d.limit();
       
      System.out.println(d.getClass().getName() +
      ": size=" + size +
      ", cap=" + cap +
      ", lim=" + lim +
      ", pos=" + pos);

         }
      -----------------------------
      result:
      java.nio.ByteBufferAsDoubleBufferB: size=945, cap=118, lim=118, pos=0
      -----------------------------

      Similar behavior for other view buffers (CharBuffer, IntBuffer ..).


            mr Mark Reinhold
            hvilekar Harshad Vilekar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: