RFR: 8321180: Condition for non-latin1 string size too large exception is off by one
Raffaello Giulietti
rgiulietti at openjdk.org
Fri Dec 8 19:35:15 UTC 2023
On Fri, 8 Dec 2023 16:28:21 GMT, ExE Boss <duke at openjdk.org> wrote:
>> In the compact string implementation of non-latin1 (UTF16) strings the length is constrained by VM implementation limit on the size a byte array that can be allocated. To produce a useful exception the implementation checks the string size against the maximum byte array size. The exception message is correct
>>
>> "UTF16 String size is " + len + ", should be less than or equal to " + MAX_LENGTH
>>
>> The code should match the message, otherwise the exception thrown is:
>>
>> java.lang.OutOfMemoryError: Requested array size exceeds VM limit
>
> src/java.base/share/classes/java/lang/StringUTF16.java line 59:
>
>> 57: if (len >= MAX_LENGTH) {
>> 58: throw new OutOfMemoryError("UTF16 String size is " + len +
>> 59: ", should be less than or equal to " + MAX_LENGTH);
>
> Suggestion:
>
> ", should be less than " + MAX_LENGTH);
I second @ExE-Boss's comment.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17008#discussion_r1420935417
More information about the core-libs-dev
mailing list