提交 424ededc 编写于 作者: A alanb

7000913: (bf) CharBuffer.wrap, slice, position, slice leads to CharBuffer with incorrect offser

Reviewed-by: forax
上级 28c5302b
......@@ -47,7 +47,7 @@ class StringCharBuffer // package-private
0,
this.remaining(),
this.remaining(),
this.position());
offset + this.position());
}
private StringCharBuffer(CharSequence s,
......
......@@ -22,7 +22,7 @@
*/
/* @test
* @bug 4997655
* @bug 4997655 7000913
* @summary (bf) CharBuffer.slice() on wrapped CharSequence results in wrong position
*/
......@@ -75,12 +75,27 @@ public class StringCharBufferSliceTest {
}
}
System.out.println(
">>> StringCharBufferSliceTest-main: testing slice with result of slice");
buff.position(0);
buff.limit(buff.capacity());
slice = buff.slice();
for (int i=0; i<4; i++) {
slice.position(i);
CharBuffer nextSlice = slice.slice();
if (nextSlice.position() != 0)
throw new RuntimeException("New buffer's position should be zero");
if (!nextSlice.equals(slice))
throw new RuntimeException("New buffer should be equal");
slice = nextSlice;
}
System.out.println(
">>> StringCharBufferSliceTest-main: testing toString.");
buff.position(4);
buff.limit(7);
slice = buff.slice();
if (! slice.toString().equals("tes")) {
if (!slice.toString().equals("tes")) {
throw new RuntimeException("bad toString() after slice(): " + slice.toString());
}
......@@ -104,6 +119,7 @@ public class StringCharBufferSliceTest {
|| dupe.charAt(2) != 's' || dupe.charAt(3) != 't') {
throw new RuntimeException("bad duplicate() after slice(): '" + dupe + "'");
}
System.out.println(">>> StringCharBufferSliceTest-main: done!");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册