Skip to content

Commit

Permalink
8322512: StringBuffer.repeat does not work correctly after toString()…
Browse files Browse the repository at this point in the history
… was called

Reviewed-by: prappo, redestad
Backport-of: df22fb322e6c4c9931a770bd0abf4c43b83c4e4a
  • Loading branch information
Jim Laskey committed Jan 17, 2024
1 parent 78150ca commit 60c68a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/java.base/share/classes/java/lang/StringBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
15 changes: 14 additions & 1 deletion test/jdk/java/lang/StringBuilder/StringBufferRepeat.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 60c68a1

Please sign in to comment.