FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Linux moonlight 2.6.20-14-generic #2 SMP Mon Apr 2 20:37:49 UTC 2007 i686 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
When slicing a CharSequence wrapping CharBuffer, the resulting CharBuffer appears to be incorrect. According to the specs, the resulting sliced buffer should start at the original buffer's position. So, slicing 'Hello World' at position 4 and limit 7 should create a buffer that has 'o W' in it. But instead it has 'Hel'. This is demonstrated by the following testcase. Wrapping a char array instead shows the expected result.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try attached test program.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Wrapping the char sequence should yield 'o W'
ACTUAL -
Wrapping the char sequence yields 'Hel'
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.nio.CharBuffer;
public class TestCharSequenceBuffer {
public static void main(String[] args) {
CharBuffer cb = CharBuffer.wrap("Hello World");
cb.position(4);
cb.limit(7);
CharBuffer sl = cb.slice();
System.out.println("wrapping a CharSequence");
System.out.println("expected: 'o', result: '" + sl.get() + "'");
System.out.println("expected: ' ', result: '" + sl.get() + "'");
System.out.println("expected: 'W', result: '" + sl.get() + "'");
cb = CharBuffer.wrap("Hello World".toCharArray());
cb.position(4);
cb.limit(7);
sl = cb.slice();
System.out.println("wrapping a char[]");
System.out.println("expected: 'o', result: '" + sl.get() + "'");
System.out.println("expected: ' ', result: '" + sl.get() + "'");
System.out.println("expected: 'W', result: '" + sl.get() + "'");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Convert the char sequence to a char[] and wrap this.
Release Regression From : 5.0u10
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.