You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2025/08/30 17:37:00 UTC

[jira] [Resolved] (TEXT-236) Inserting at end of a TextStringBuilder throws a StringIndexOutOfBoundsException

     [ https://issues.apache.org/jira/browse/TEXT-236?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory resolved TEXT-236.
----------------------------------
    Resolution: Fixed

Hello [~pierrepost] 

This is now fixed in git master and snapshot builds (https://repository.apache.org/content/repositories/snapshots/)

Please verify your use case.

TY!

 

> Inserting at end of a TextStringBuilder throws a StringIndexOutOfBoundsException
> --------------------------------------------------------------------------------
>
>                 Key: TEXT-236
>                 URL: https://issues.apache.org/jira/browse/TEXT-236
>             Project: Commons Text
>          Issue Type: Bug
>    Affects Versions: 1.13.0, 1.13.1
>            Reporter: Pierre Post
>            Priority: Major
>
> The methods
> {{TextStringBuilder#insert(...)}}
> throw a {{StringIndexOutOfBoundsException}} when you try to insert something at the end of the buffer. Nevertheless, the documentation of {{validateIndex()}} still states "{_}Validates that an index is in the range 0 <= index *<=* size.{_}"
> I think this is really an unexpected behavior and also differs from the behavior from {{java.lang.StringBuilder}} and {{{}org.apache.commons.text.StrBuilder{}}}, as the following example shows:
> {code:java}
> StringBuilder stringBuilder = new StringBuilder();
> // works as expected
> stringBuilder.insert(0, "test");
> StrBuilder strBuilder = new StrBuilder();
> // works as expected
> strBuilder.insert(0, "test");
> TextStringBuilder textStringBuilder = new TextStringBuilder();
> // throws java.lang.StringIndexOutOfBoundsException: String index out of range: 0
> textStringBuilder.insert(0, "test");
> {code}
> However, care must be taken, as {{validateIndex()}} is also used by the various char methods (e.g. {{{}setCharAt(){}}}) where the current validation IS justified. Validation should be separated for these two use cases so that insertion at the end of the buffer is again possible.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)