changeset 5293:5209ecd67995

7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown Reviewed-by: alanb
author luchsh
date Mon, 13 Aug 2012 19:51:48 +0800
parents a18d0a3ac45b
children 09b0d78dfde9
files src/share/classes/java/nio/X-Buffer.java.template test/java/nio/Buffer/Basic-X.java.template test/java/nio/Buffer/Basic.java test/java/nio/Buffer/BasicByte.java test/java/nio/Buffer/BasicChar.java test/java/nio/Buffer/BasicDouble.java test/java/nio/Buffer/BasicFloat.java test/java/nio/Buffer/BasicInt.java test/java/nio/Buffer/BasicLong.java test/java/nio/Buffer/BasicShort.java
diffstat 10 files changed, 107 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/nio/X-Buffer.java.template	Thu Nov 24 11:34:31 2011 +0000
+++ b/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/test/java/nio/Buffer/Basic-X.java.template	Thu Nov 24 11:34:31 2011 +0000
+++ b/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/test/java/nio/Buffer/Basic.java	Thu Nov 24 11:34:31 2011 +0000
+++ b/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/test/java/nio/Buffer/BasicByte.java	Thu Nov 24 11:34:31 2011 +0000
+++ b/test/java/nio/Buffer/BasicByte.java	Mon Aug 13 19:51:48 2012 +0800
@@ -404,6 +404,19 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
         // Compact
 
         relPut(b);
--- a/test/java/nio/Buffer/BasicChar.java	Thu Nov 24 11:34:31 2011 +0000
+++ b/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/test/java/nio/Buffer/BasicDouble.java	Thu Nov 24 11:34:31 2011 +0000
+++ b/test/java/nio/Buffer/BasicDouble.java	Mon Aug 13 19:51:48 2012 +0800
@@ -404,6 +404,19 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
         // Compact
 
         relPut(b);
--- a/test/java/nio/Buffer/BasicFloat.java	Thu Nov 24 11:34:31 2011 +0000
+++ b/test/java/nio/Buffer/BasicFloat.java	Mon Aug 13 19:51:48 2012 +0800
@@ -404,6 +404,19 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
         // Compact
 
         relPut(b);
--- a/test/java/nio/Buffer/BasicInt.java	Thu Nov 24 11:34:31 2011 +0000
+++ b/test/java/nio/Buffer/BasicInt.java	Mon Aug 13 19:51:48 2012 +0800
@@ -404,6 +404,19 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
         // Compact
 
         relPut(b);
--- a/test/java/nio/Buffer/BasicLong.java	Thu Nov 24 11:34:31 2011 +0000
+++ b/test/java/nio/Buffer/BasicLong.java	Mon Aug 13 19:51:48 2012 +0800
@@ -404,6 +404,19 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
         // Compact
 
         relPut(b);
--- a/test/java/nio/Buffer/BasicShort.java	Thu Nov 24 11:34:31 2011 +0000
+++ b/test/java/nio/Buffer/BasicShort.java	Mon Aug 13 19:51:48 2012 +0800
@@ -404,6 +404,19 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
         // Compact
 
         relPut(b);