RFR: 8302590: Add String.indexOf(int ch, int fromIndex, int toIndex) [v4]

Alan Bateman alanb at openjdk.org
Wed Mar 1 18:57:24 UTC 2023


On Wed, 1 Mar 2023 16:24:46 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:

>> Add an `indexOf()` variant allowing to specify both a lower and an upper bound on the search.
>
> Raffaello Giulietti has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8302590: Add String.indexOf(int ch, int fromIndex, int toIndex)

src/java.base/share/classes/java/lang/String.java line 2435:

> 2433:      * @apiNote
> 2434:      * An invocation of this method returns -1 when {@code fromIndex} happens
> 2435:      * to be too large. The result is thus indistinguishable from a genuine

Adding an apiNote to the existing indexOf(int, int) is good but I think it will need a bit word smithing, e.g. "happens to be too large" is a bit too casual. I think I would start with saying the method returns -1 if fromFrom is negative or >= the string length, it does not throw an exception if called with an out of range index.

src/java.base/share/classes/java/lang/String.java line 2484:

> 2482:      *          is negative, or {@code toIndex} is larger than the length of
> 2483:      *          this {@code String} object, or {@code fromIndex} is larger than
> 2484:      *          {@code toIndex}.

Thanks for the update, I think you've got to a good place.

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

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


More information about the core-libs-dev mailing list