7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
authorluchsh
Mon, 13 Aug 2012 19:51:48 +0800
changeset 13563 13c8e8f0302b
parent 13562 a53860ac26e0
child 13564 3571e232ab03
7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown Reviewed-by: alanb
jdk/src/share/classes/java/nio/X-Buffer.java.template
jdk/test/java/nio/Buffer/Basic-X.java.template
jdk/test/java/nio/Buffer/Basic.java
jdk/test/java/nio/Buffer/BasicByte.java
jdk/test/java/nio/Buffer/BasicChar.java
jdk/test/java/nio/Buffer/BasicDouble.java
jdk/test/java/nio/Buffer/BasicFloat.java
jdk/test/java/nio/Buffer/BasicInt.java
jdk/test/java/nio/Buffer/BasicLong.java
jdk/test/java/nio/Buffer/BasicShort.java
--- a/jdk/src/share/classes/java/nio/X-Buffer.java.template	Sun Aug 12 22:56:45 2012 +0100
+++ b/jdk/src/share/classes/java/nio/X-Buffer.java.template	Mon Aug 13 19:51:48 2012 +0800
@@ -888,6 +888,8 @@
      */
     public $Type$Buffer put(String src, int start, int end) {
         checkBounds(start, end - start, src.length());
+        if (end - start > remaining())
+            throw new BufferOverflowException();
         for (int i = start; i < end; i++)
             this.put(src.charAt(i));
         return this;
--- a/jdk/test/java/nio/Buffer/Basic-X.java.template	Sun Aug 12 22:56:45 2012 +0100
+++ b/jdk/test/java/nio/Buffer/Basic-X.java.template	Mon Aug 13 19:51:48 2012 +0800
@@ -402,6 +402,19 @@
         ck(b, b.charAt(1), 'f');
         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]
 
         // Compact
--- a/jdk/test/java/nio/Buffer/Basic.java	Sun Aug 12 22:56:45 2012 +0100
+++ b/jdk/test/java/nio/Buffer/Basic.java	Mon Aug 13 19:51:48 2012 +0800
@@ -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 6795561
+ *      6221101 6234263 6535542 6591971 6593946 6795561 7190219
  * @author Mark Reinhold
  */
 
--- a/jdk/test/java/nio/Buffer/BasicByte.java	Sun Aug 12 22:56:45 2012 +0100
+++ b/jdk/test/java/nio/Buffer/BasicByte.java	Mon Aug 13 19:51:48 2012 +0800
@@ -404,6 +404,19 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
         // Compact
 
         relPut(b);
--- a/jdk/test/java/nio/Buffer/BasicChar.java	Sun Aug 12 22:56:45 2012 +0100
+++ b/jdk/test/java/nio/Buffer/BasicChar.java	Mon Aug 13 19:51:48 2012 +0800
@@ -402,6 +402,19 @@
         ck(b, b.charAt(1), 'f');
         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
--- a/jdk/test/java/nio/Buffer/BasicDouble.java	Sun Aug 12 22:56:45 2012 +0100
+++ b/jdk/test/java/nio/Buffer/BasicDouble.java	Mon Aug 13 19:51:48 2012 +0800
@@ -404,6 +404,19 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
         // Compact
 
         relPut(b);
--- a/jdk/test/java/nio/Buffer/BasicFloat.java	Sun Aug 12 22:56:45 2012 +0100
+++ b/jdk/test/java/nio/Buffer/BasicFloat.java	Mon Aug 13 19:51:48 2012 +0800
@@ -404,6 +404,19 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
         // Compact
 
         relPut(b);
--- a/jdk/test/java/nio/Buffer/BasicInt.java	Sun Aug 12 22:56:45 2012 +0100
+++ b/jdk/test/java/nio/Buffer/BasicInt.java	Mon Aug 13 19:51:48 2012 +0800
@@ -404,6 +404,19 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
         // Compact
 
         relPut(b);
--- a/jdk/test/java/nio/Buffer/BasicLong.java	Sun Aug 12 22:56:45 2012 +0100
+++ b/jdk/test/java/nio/Buffer/BasicLong.java	Mon Aug 13 19:51:48 2012 +0800
@@ -404,6 +404,19 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
         // Compact
 
         relPut(b);
--- a/jdk/test/java/nio/Buffer/BasicShort.java	Sun Aug 12 22:56:45 2012 +0100
+++ b/jdk/test/java/nio/Buffer/BasicShort.java	Mon Aug 13 19:51:48 2012 +0800
@@ -404,6 +404,19 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
         // Compact
 
         relPut(b);