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

(bf) capacity() returns 0 when a value was expected

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.0
    • core-libs
    • sparc
    • solaris_7

      Called wrap(String str, int start, int end) with start and end values equal to 0
      And str as "This is a test string".
      For the CharBuffer returned by this method, capacity() returns 0, instead of returning the size of the string.
      As according to spec, CharBuffer created by calling wrap(String str, int start, int end) " The buffer's capacity will be str.length()"

      String source = "This is a test string";
      CharBuffer c = CharBuffer.wrap(source,0,0);
      System.out.println("Capacity is: "+c.capacity());

      results
      Capacity is: 0
      ----------------------------------------------------------------------

      String source = "This is a test string used to test wrap()";
      int size = source.length();
      CharBuffer c = CharBuffer.wrap(source,10,size);
      System.out.println("Position :"+c.capacity()+" Expected : "+size);

      results in
      capacity :31 Expected: 41

      according to Specs
      wrap(String str,int start,int end) wraps a string into a Buffer and its capacity will be str.length()

            iris Iris Clark
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: