提交 2e5f4127 编写于 作者: A alanb

6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer

Reviewed-by: sherman, iris
上级 178d7fa4
......@@ -196,10 +196,12 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
if ((start < 0) || (end > len) || (start > end))
throw new IndexOutOfBoundsException();
int sublen = end - start;
int off = offset + ((pos + start) << $LG_BYTES_PER_VALUE$);
assert (off >= 0);
return new ByteBufferAsCharBuffer$RW$$BO$(bb, -1, 0, sublen, sublen, off);
return new ByteBufferAsCharBuffer$RW$$BO$(bb,
-1,
pos + start,
pos + end,
capacity(),
offset);
}
#end[char]
......
......@@ -412,10 +412,12 @@ class Direct$Type$Buffer$RW$$BO$
if ((start < 0) || (end > len) || (start > end))
throw new IndexOutOfBoundsException();
int sublen = end - start;
int off = (pos + start) << $LG_BYTES_PER_VALUE$;
assert (off >= 0);
return new DirectCharBuffer$RW$$BO$(this, -1, 0, sublen, sublen, off);
return new DirectCharBuffer$RW$$BO$(this,
-1,
pos + start,
pos + end,
capacity(),
offset);
}
#end[char]
......
......@@ -572,10 +572,13 @@ class Heap$Type$Buffer$RW$
|| (end > length())
|| (start > end))
throw new IndexOutOfBoundsException();
int len = end - start;
int pos = position();
return new HeapCharBuffer$RW$(hb,
-1, 0, len, len,
offset + position() + start);
-1,
pos + start,
pos + end,
capacity(),
offset);
}
#end[char]
......
......@@ -102,10 +102,12 @@ class StringCharBuffer // package-private
public final CharBuffer subSequence(int start, int end) {
try {
int pos = position();
return new StringCharBuffer(str, -1,
return new StringCharBuffer(str,
-1,
pos + checkIndex(start, pos),
pos + checkIndex(end, pos),
remaining(), offset);
capacity(),
offset);
} catch (IllegalArgumentException x) {
throw new IndexOutOfBoundsException();
}
......
......@@ -365,8 +365,11 @@ public class Basic$Type$
b.position(2);
ck(b, b.charAt(1), 'd');
CharBuffer c = (CharBuffer)b.subSequence(1, 4);
ck(b, b.subSequence(1, 4).toString().equals("def"));
CharBuffer c = b.subSequence(1, 4);
ck(c, c.capacity(), b.capacity());
ck(c, c.position(), b.position()+1);
ck(c, c.limit(), b.position()+4);
ck(c, b.subSequence(1, 4).toString().equals("def"));
// 4938424
b.position(4);
......@@ -722,6 +725,8 @@ public class Basic$Type$
ck(b, start, b.position());
ck(b, end, b.limit());
ck(b, s.length(), b.capacity());
b.position(6);
ck(b, b.subSequence(0,3).toString().equals("ghi"));
// The index, relative to the position, must be non-negative and
// smaller than remaining().
......
......@@ -25,7 +25,7 @@
* @summary Unit test for buffers
* @bug 4413135 4414911 4416536 4416562 4418782 4471053 4472779 4490253 4523725
* 4526177 4463011 4660660 4661219 4663521 4782970 4804304 4938424 6231529
* 6221101 6234263 6535542 6591971 6593946
* 6221101 6234263 6535542 6591971 6593946 6795561
* @author Mark Reinhold
*/
......
......@@ -371,6 +371,9 @@ public class BasicByte
......@@ -783,6 +786,8 @@ public class BasicByte
......
......@@ -365,8 +365,11 @@ public class BasicChar
b.position(2);
ck(b, b.charAt(1), 'd');
CharBuffer c = (CharBuffer)b.subSequence(1, 4);
ck(b, b.subSequence(1, 4).toString().equals("def"));
CharBuffer c = b.subSequence(1, 4);
ck(c, c.capacity(), b.capacity());
ck(c, c.position(), b.position()+1);
ck(c, c.limit(), b.position()+4);
ck(c, b.subSequence(1, 4).toString().equals("def"));
// 4938424
b.position(4);
......@@ -722,6 +725,8 @@ public class BasicChar
ck(b, start, b.position());
ck(b, end, b.limit());
ck(b, s.length(), b.capacity());
b.position(6);
ck(b, b.subSequence(0,3).toString().equals("ghi"));
// The index, relative to the position, must be non-negative and
// smaller than remaining().
......
......@@ -371,6 +371,9 @@ public class BasicDouble
......@@ -783,6 +786,8 @@ public class BasicDouble
......
......@@ -371,6 +371,9 @@ public class BasicFloat
......@@ -783,6 +786,8 @@ public class BasicFloat
......
......@@ -371,6 +371,9 @@ public class BasicInt
......@@ -783,6 +786,8 @@ public class BasicInt
......
......@@ -371,6 +371,9 @@ public class BasicLong
......@@ -783,6 +786,8 @@ public class BasicLong
......
......@@ -371,6 +371,9 @@ public class BasicShort
......@@ -783,6 +786,8 @@ public class BasicShort
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册