7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown

Reviewed-by: alanb
This commit is contained in:
Jonathan Lu 2012-08-13 19:51:48 +08:00
parent d947b5d95a
commit f349c3da24
10 changed files with 107 additions and 1 deletions

View file

@ -888,6 +888,8 @@ public abstract class $Type$Buffer
*/ */
public $Type$Buffer put(String src, int start, int end) { public $Type$Buffer put(String src, int start, int end) {
checkBounds(start, end - start, src.length()); checkBounds(start, end - start, src.length());
if (end - start > remaining())
throw new BufferOverflowException();
for (int i = start; i < end; i++) for (int i = start; i < end; i++)
this.put(src.charAt(i)); this.put(src.charAt(i));
return this; return this;

View file

@ -402,6 +402,19 @@ public class Basic$Type$
ck(b, b.charAt(1), 'f'); ck(b, b.charAt(1), 'f');
ck(b, b.subSequence(1, 3).toString().equals("fg")); ck(b, b.subSequence(1, 3).toString().equals("fg"));
// String ops
// 7190219
b.clear();
int pos = b.position();
tryCatch(b, BufferOverflowException.class, new Runnable() {
public void run() {
b.put(String.valueOf(new char[b.capacity() + 1]), 0,
b.capacity() + 1);
}});
ck(b, b.position(), pos);
relGet(b);
#end[char] #end[char]
// Compact // Compact

View file

@ -25,7 +25,7 @@
* @summary Unit test for buffers * @summary Unit test for buffers
* @bug 4413135 4414911 4416536 4416562 4418782 4471053 4472779 4490253 4523725 * @bug 4413135 4414911 4416536 4416562 4418782 4471053 4472779 4490253 4523725
* 4526177 4463011 4660660 4661219 4663521 4782970 4804304 4938424 6231529 * 4526177 4463011 4660660 4661219 4663521 4782970 4804304 4938424 6231529
* 6221101 6234263 6535542 6591971 6593946 6795561 * 6221101 6234263 6535542 6591971 6593946 6795561 7190219
* @author Mark Reinhold * @author Mark Reinhold
*/ */

View file

@ -396,6 +396,19 @@ public class BasicByte

View file

@ -402,6 +402,19 @@ public class BasicChar
ck(b, b.charAt(1), 'f'); ck(b, b.charAt(1), 'f');
ck(b, b.subSequence(1, 3).toString().equals("fg")); ck(b, b.subSequence(1, 3).toString().equals("fg"));
// String ops
// 7190219
b.clear();
int pos = b.position();
tryCatch(b, BufferOverflowException.class, new Runnable() {
public void run() {
b.put(String.valueOf(new char[b.capacity() + 1]), 0,
b.capacity() + 1);
}});
ck(b, b.position(), pos);
relGet(b);
// Compact // Compact

View file

@ -396,6 +396,19 @@ public class BasicDouble

View file

@ -396,6 +396,19 @@ public class BasicFloat

View file

@ -396,6 +396,19 @@ public class BasicInt

View file

@ -396,6 +396,19 @@ public class BasicLong

View file

@ -396,6 +396,19 @@ public class BasicShort