RFR: JDK-8322512 StringBuffer.repeat does not work correctly after toString() was called

Roger Riggs rriggs at openjdk.org
Wed Dec 20 21:55:39 UTC 2023


On Wed, 20 Dec 2023 20:25:07 GMT, Jim Laskey <jlaskey at openjdk.org> wrote:

> The new repeat methods were not clearing the toStringCache.

src/java.base/share/classes/java/lang/StringBuffer.java line 719:

> 717:     public synchronized StringBuffer repeat(int codePoint, int count) {
> 718:         super.repeat(codePoint, count);
> 719:         toStringCache = null;

The other cases in StringBuffer clear toStringCache *before* performing the modification.
For consistency, I'd suggest doing the same.

src/java.base/share/classes/java/lang/StringBuffer.java line 731:

> 729:     public synchronized StringBuffer repeat(CharSequence cs, int count) {
> 730:         super.repeat(cs, count);
> 731:         toStringCache = null;

Ditto, clear toStringCache before the modification.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/17172#discussion_r1433218351
PR Review Comment: https://git.openjdk.org/jdk/pull/17172#discussion_r1433218688


More information about the core-libs-dev mailing list