< prev index next >

src/java.base/share/classes/java/lang/String.java

Print this page

        

@@ -133,11 +133,11 @@
      * Initializes a newly created {@code String} object so that it represents
      * an empty character sequence.  Note that use of this constructor is
      * unnecessary since Strings are immutable.
      */
     public String() {
-        this.value = new char[0];
+        this.value = "".value;
     }
 
     /**
      * Initializes a newly created {@code String} object so that it represents
      * the same sequence of characters as the argument; in other words, the

@@ -189,13 +189,19 @@
      */
     public String(char value[], int offset, int count) {
         if (offset < 0) {
             throw new StringIndexOutOfBoundsException(offset);
         }
+        if (count <= 0) {
         if (count < 0) {
             throw new StringIndexOutOfBoundsException(count);
         }
+            if (offset <= value.length) {
+                this.value = "".value;
+                return;
+            }
+        }
         // Note: offset or count might be near -1>>>1.
         if (offset > value.length - count) {
             throw new StringIndexOutOfBoundsException(offset + count);
         }
         this.value = Arrays.copyOfRange(value, offset, offset+count);

@@ -231,13 +237,19 @@
      */
     public String(int[] codePoints, int offset, int count) {
         if (offset < 0) {
             throw new StringIndexOutOfBoundsException(offset);
         }
+        if (count <= 0) {
         if (count < 0) {
             throw new StringIndexOutOfBoundsException(count);
         }
+            if (offset <= codePoints.length) {
+                this.value = "".value;
+                return;
+            }
+        }
         // Note: offset or count might be near -1>>>1.
         if (offset > codePoints.length - count) {
             throw new StringIndexOutOfBoundsException(offset + count);
         }
 

@@ -781,11 +793,11 @@
      * (thus the total number of characters to be copied is
      * {@code srcEnd-srcBegin}). The characters are copied into the
      * subarray of {@code dst} starting at index {@code dstBegin}
      * and ending at index:
      * <blockquote><pre>
-     *     dstbegin + (srcEnd-srcBegin) - 1
+     *     dstBegin + (srcEnd-srcBegin) - 1
      * </pre></blockquote>
      *
      * @param      srcBegin   index of the first character in the string
      *                        to copy.
      * @param      srcEnd     index after the last character in the string

@@ -826,11 +838,11 @@
      * number of characters to be copied is {@code srcEnd-srcBegin}. The
      * characters, converted to bytes, are copied into the subarray of {@code
      * dst} starting at index {@code dstBegin} and ending at index:
      *
      * <blockquote><pre>
-     *     dstbegin + (srcEnd-srcBegin) - 1
+     *     dstBegin + (srcEnd-srcBegin) - 1
      * </pre></blockquote>
      *
      * @deprecated  This method does not properly convert characters into
      * bytes.  As of JDK&nbsp;1.1, the preferred way to do this is via the
      * {@link #getBytes()} method, which uses the platform's default charset.
< prev index next >