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: rriggs, jpai
  • Loading branch information
JimLaskey committed Jan 4, 2024
1 parent c3cd1f1 commit df22fb3
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
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
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

3 comments on commit df22fb3

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JimLaskey
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk22

@openjdk
Copy link

@openjdk openjdk bot commented on df22fb3 Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JimLaskey the backport was successfully created on the branch backport-JimLaskey-df22fb32 in my personal fork of openjdk/jdk22. To create a pull request with this backport targeting openjdk/jdk22:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit df22fb32 from the openjdk/jdk repository.

The commit being backported was authored by Jim Laskey on 4 Jan 2024 and was reviewed by Roger Riggs and Jaikiran Pai.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk22:

$ git fetch https://github.com/openjdk-bots/jdk22.git backport-JimLaskey-df22fb32:backport-JimLaskey-df22fb32
$ git checkout backport-JimLaskey-df22fb32
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk22.git backport-JimLaskey-df22fb32

Please sign in to comment.