RFR: JDK-8302323 Add repeat methods to StringBuilder/StringBuffer

Jim Laskey jlaskey at openjdk.org
Thu Feb 23 17:30:34 UTC 2023


On Thu, 23 Feb 2023 16:54:10 GMT, Jim Laskey <jlaskey at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/AbstractStringBuilder.java line 1918:
>> 
>>> 1916:         }
>>> 1917:         int valueLength = length << UTF16;
>>> 1918:         if ((Integer.MAX_VALUE - this.count) / count < valueLength) {
>> 
>> I think you can omit this check; the call to ensureCapacityInternal will guard against the needed size.
>
> You may be right - I looked over ensureCapacityInternal a few times, just noticing the signed shift. Thx.

Nope - because of the int multiple ensureCapacityInternal doesn't handle it.

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

PR: https://git.openjdk.org/jdk/pull/12728


More information about the core-libs-dev mailing list