JDK-4415483 : (bf) buffer created by CharBuffer.subSequence() has different values for cap,lim
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_7
  • CPU: sparc
  • Submitted: 2001-02-15
  • Updated: 2001-08-16
  • Resolved: 2001-08-09
Related Reports
Duplicate :  
Relates :  
Description
Specification for CharBuffer.subSequence(int start, int end) says "new buffer's capacity will be that of this buffer, its position will be position() + start, and its limit will be position() + end."

But in actual new buffer's capacity, limit and position values are different from what spec says.
 
String source = "This is the string used to test subSequence() method";
CharBuffer c = CharBuffer.wrap(source.toCharArray());
int position = 5;
int start = 5;
int end = 10;
c.position(position);
CharBuffer cNew = (CharBuffer)(c.subSequence(start,end));
int pos = c.position()+start;
int lim = c.position()+end;
System.out.println("position: "+cNew.position()+" Expected: "+pos);
System.out.println("limit: "+cNew.limit()+" Expected: "+lim);
System.out.println("capacity: "+cNew.capacity()+" Expected: "+c.capacity());

results in
position: 0 Expected: 10
limit: 5 Expected: 15
capacity: 5 Expected: 52

Comments
EVALUATION Duplicate 4416536. -- iag@eng 2001-08-09
09-08-2001