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

Claes Redestad claes.redestad at oracle.com
Thu Aug 8 13:56:44 UTC 2019


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.


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