On Tue, 28 Feb 2023 07:50:18 GMT, Tagir F. Valeev <tval...@openjdk.org> wrote:

>> Jim Laskey has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Optimize for empty CharSequence
>
> src/java.base/share/classes/java/lang/AbstractStringBuilder.java line 1879:
> 
>> 1877:      * @since 21
>> 1878:      * @throws IllegalArgumentException  if {@code count} is less than 
>> zero
>> 1879:      * @throws IndexOutOfBoundsException  if the result overflows the 
>> buffer
> 
> Can `IndexOutOfBoundsException` be really thrown? We don't have any index 
> here. From the implementation I see that only `OutOfMemoryError` and 
> `IllegalArgumentException` can be thrown.
> 
> Also, I see a small descrepancy between messages in this method and 
> `String.repeat`. The latter has:
> 
> 
>      * @throws  IllegalArgumentException if the {@code count} is
>      *          negative.
>      *
>      * @since 11
>      */
>     public String repeat(int count) {
>         if (count < 0) {
>             throw new IllegalArgumentException("count is negative: " + count);
>         }
> 
> 
> Probably it's better to reuse the same wording ("is negative" instead of "is 
> less than zero") for consistency?

You are correct about `IndexOutOfBoundsException`. Earlier versions used 
methods that threw `IndexOutOfBoundsException`. Also, changing to "is negative"

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

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

Reply via email to