RFR (XS) 8221307 : String.substring() OOB exception on start index reports improper information

Roger Riggs Roger.Riggs at oracle.com
Tue Aug 13 20:09:44 UTC 2019


Hi Ivan,

Looks good.

Thanks, Roger


On 8/13/19 3:55 PM, Ivan Gerasimov wrote:
> Hello!
>
> A simple benchmark did not detect any negative impact of delegating 
> substring(int) to substring(int, int):
>
> Before fix:
> Benchmark                     Mode  Cnt   Score   Error Units
> StringSubstring.from26toEnd0  avgt   12  20.279 ± 0.306 ns/op
> StringSubstring.from26toEnd1  avgt   12  20.677 ± 1.924 ns/op
>
> After fix:
> Benchmark                     Mode  Cnt   Score   Error Units
> StringSubstring.from26toEnd0  avgt   12  19.835 ± 0.135 ns/op
> StringSubstring.from26toEnd1  avgt   12  20.784 ± 1.791 ns/op
>
>
> So here's the updated webrev: 
> http://cr.openjdk.java.net/~igerasim/8221307/01/webrev/
>
> Will you approve it to go?
>
> With kind regards,
>
> Ivan
>
>
> On 8/8/19 6:56 AM, Claes Redestad wrote:
>> Hi,
>>
>> perhaps a stupid question, but why isn't String::substring(int) 
>> calling substring(beginIndex, length())? That'd ensure consistent error
>> messages, but otherwise preserve semantics.
>>
>> /Claes
>>
>> On 2019-08-08 02:17, Ivan Gerasimov wrote:
>>> Hello!
>>>
>>> The exception thrown by substring(int) may look confusing.
>>> For example it produces "String index out of range: -1" when the 
>>> index is length+1.
>>>
>>> It is proposed to make the error message more clear, similar to what 
>>> we have for substring(int, int).
>>>
>>> BUGURL: https://bugs.openjdk.java.net/browse/JDK-8221307
>>> WEBREV: http://cr.openjdk.java.net/~igerasim/8221307/00/webrev/
>>>
>>> Would you please help review?
>>>
>>



More information about the core-libs-dev mailing list