diff --git a/src/java.base/share/classes/java/lang/StringBuffer.java b/src/java.base/share/classes/java/lang/StringBuffer.java index ec7ecb5d245..d77462f0c70 100644 --- a/src/java.base/share/classes/java/lang/StringBuffer.java +++ b/src/java.base/share/classes/java/lang/StringBuffer.java @@ -715,6 +715,7 @@ public synchronized StringBuffer reverse() { */ @Override public synchronized StringBuffer repeat(int codePoint, int count) { + toStringCache = null; super.repeat(codePoint, count); return this; } @@ -726,6 +727,7 @@ public synchronized StringBuffer repeat(int codePoint, int count) { */ @Override public synchronized StringBuffer repeat(CharSequence cs, int count) { + toStringCache = null; super.repeat(cs, count); return this; } diff --git a/test/jdk/java/lang/StringBuilder/StringBufferRepeat.java b/test/jdk/java/lang/StringBuilder/StringBufferRepeat.java index 2d1f3c64f60..d78066fb417 100644 --- a/test/jdk/java/lang/StringBuilder/StringBufferRepeat.java +++ b/test/jdk/java/lang/StringBuilder/StringBufferRepeat.java @@ -29,7 +29,7 @@ /** * @test - * @bug 8302323 + * @bug 8302323 8322512 * @summary Test StringBuffer.repeat sanity tests * @run testng/othervm -XX:-CompactStrings StringBufferRepeat * @run testng/othervm -XX:+CompactStrings StringBufferRepeat @@ -129,6 +129,19 @@ public void sanity() { expected = "\u0000\u0000\u0000\u0000\u0000\u0000\u0020\u0020\u0020\u0020\u0020\u0020\u2461\u2462\u2462\u2462\u2462\u2462\udbff\udfff\udbff\udfff\udbff\udfff\udbff\udfff\udbff\udfff\udbff\udfff"; assertEquals(expected, sb.toString()); + // toStringCache + + sb.setLength(0); + sb.toString(); + sb.repeat('*', 5); + expected = "*****"; + assertEquals(sb.toString(), expected); + sb.setLength(0); + sb.toString(); + sb.repeat("*", 5); + assertEquals(sb.toString(), expected); + + } public void exceptions() {