8134424: BlockDataInputStream.readUTFBody: size local StringBuffer with the given length
authorchegar
Mon, 15 Feb 2016 14:25:21 +0000
changeset 35788 04c8859c969b
parent 35787 39cff2356d03
child 35789 4a0184327358
8134424: BlockDataInputStream.readUTFBody: size local StringBuffer with the given length Reviewed-by: rriggs, shade
jdk/src/java.base/share/classes/java/io/ObjectInputStream.java
--- a/jdk/src/java.base/share/classes/java/io/ObjectInputStream.java	Mon Feb 15 10:14:39 2016 +0000
+++ b/jdk/src/java.base/share/classes/java/io/ObjectInputStream.java	Mon Feb 15 14:25:21 2016 +0000
@@ -3144,7 +3144,15 @@
          * utflen bytes.
          */
         private String readUTFBody(long utflen) throws IOException {
-            StringBuilder sbuf = new StringBuilder();
+            StringBuilder sbuf;
+            if (utflen > 0 && utflen < Integer.MAX_VALUE) {
+                // a reasonable initial capacity based on the UTF length
+                int initialCapacity = Math.min((int)utflen, 0xFFFF);
+                sbuf = new StringBuilder(initialCapacity);
+            } else {
+                sbuf = new StringBuilder();
+            }
+
             if (!blkmode) {
                 end = pos = 0;
             }