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

Alan Bateman alanb at openjdk.org
Mon Jan 19 19:36:22 UTC 2026


On Mon, 19 Jan 2026 08:14:11 GMT, Liam Miller-Cushon <cushon at openjdk.org> wrote:

> The motivating use cases I've seen for this method are to compute the length of encoded data that contains strings, where the strings would be encoded with `getBytes`. The CSR gives the example of encoding multiple large strings into a single array. Specifying the output in terms of `getBytes(cs).length` is necessary for that use-case, and requires the handling of replacement characters and unpaired surrogates to be the same between the two methods. Do you see alternatives that should be considered?

The comment wasn't questing the addition. Instead we are saying that there is no mention of coding-error actions. More specifically, I think we should insert a sentence before "The result will be the same ..." to say that the returned length takes account of the replacement of malformed-input and unmappable-character sequences with the charset's default replacement byte array.

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

PR Comment: https://git.openjdk.org/jdk/pull/28454#issuecomment-3769823410


More information about the core-libs-dev mailing list