RFR: 8302590: Add String.indexOf(int ch, int fromIndex, int toIndex) [v2]
Alan Bateman
alanb at openjdk.org
Mon Feb 27 11:05:06 UTC 2023
On Mon, 27 Feb 2023 09:37:57 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:
>> @rgiulietti That's surprising, but if it is as you say, then the indexOf with or without the endIndex should behave identically and not throw.
>
> @viktorklang-ora I agree that the behavior w.r.t. out-of-range indices is at odd with the `substring()` family, but this inconsistency is already present since the dawn of time ;-)
Consistency with the indexOf/lastIndexOf methods is good, it makes it look like the method has been there since JDK 1.0. At the same time, it could mean that bugs go undetected, e.g. it would be easy to assume the range is fromIndex + length or to specify the parameters in the wrong order. I don't know if you explored other options but if the new method had a new name then maybe you have the option to throw for out of range index values.
-------------
PR: https://git.openjdk.org/jdk/pull/12600
More information about the core-libs-dev
mailing list