RFR: 8372353: API to compute the byte length of a String encoded in a given Charset [v7]

Roger Riggs rriggs at openjdk.org
Thu Jan 15 20:27:57 UTC 2026


On Thu, 15 Jan 2026 17:51:57 GMT, Liam Miller-Cushon <cushon at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/String.java line 1498:
>> 
>>> 1496:             if (length > (long)Integer.MAX_VALUE) {
>>> 1497:                 throw new IllegalStateException("Required length exceeds implementation limit");
>>> 1498:             }
>> 
>> This is more like a should never reach here; the OOME thrown by encodedLengthUTF8_UTF16 should ocur.
>> IllegalStateException usually refers to a programming error.
>> The other occurrence like this throws OOME.
>
> Thanks, what do you think about refactoring the OOME into `encodedLengthUTF8_UTF16` and having it return `int`?

That's fine, the `long` return was to simplify handling of too large returns.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28454#discussion_r2695831889


More information about the core-libs-dev mailing list