--- old/src/java.base/share/classes/java/lang/String.java 2014-12-19 15:07:59.040086191 +0100 +++ new/src/java.base/share/classes/java/lang/String.java 2014-12-19 15:07:58.896088002 +0100 @@ -135,7 +135,7 @@ * unnecessary since Strings are immutable. */ public String() { - this.value = new char[0]; + this.value = "".value; } /** @@ -198,7 +198,11 @@ if (offset > value.length - count) { throw new StringIndexOutOfBoundsException(offset + count); } - this.value = Arrays.copyOfRange(value, offset, offset+count); + if (count > 0) { + this.value = Arrays.copyOfRange(value, offset, offset+count); + } else { + this.value = "".value; + } } /** @@ -243,29 +247,33 @@ final int end = offset + count; - // Pass 1: Compute precise size of char[] - int n = count; - for (int i = offset; i < end; i++) { + if (count > 0) { + // Pass 1: Compute precise size of char[] + int n = count; + for (int i = offset; i < end; i++) { int c = codePoints[i]; if (Character.isBmpCodePoint(c)) continue; else if (Character.isValidCodePoint(c)) n++; - else throw new IllegalArgumentException(Integer.toString(c)); - } + else throw new IllegalArgumentException(Integer.toString(c)); + } - // Pass 2: Allocate and fill in char[] - final char[] v = new char[n]; + // Pass 2: Allocate and fill in char[] + final char[] v = new char[n]; - for (int i = offset, j = 0; i < end; i++, j++) { - int c = codePoints[i]; - if (Character.isBmpCodePoint(c)) - v[j] = (char)c; - else - Character.toSurrogates(c, v, j++); + for (int i = offset, j = 0; i < end; i++, j++) { + int c = codePoints[i]; + if (Character.isBmpCodePoint(c)) + v[j] = (char)c; + else + Character.toSurrogates(c, v, j++); + } + + this.value = v; + } else { + this.value = "".value; } - - this.value = v; } /**