RFR: 8329623: NegativeArraySizeException encoding large String to UTF-8

Naoto Sato naoto at openjdk.org
Fri Apr 5 20:20:08 UTC 2024


On Fri, 5 Apr 2024 17:44:38 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

> When encoding a vary large string in String.getBytes(StandardCharset.UTF_8) computation of the buffer size may exceed the range of a positive 32-bit Integer.
> If the estimated size for the result byte array is too large, pre-compute the exact buffer size. 
> If that exceeds the range, then throw OutOfMemoryError.

LGTM. The test case could be more thorough if it tests strings with supplementary codepoints, as the new method computes them exclusively.

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

Marked as reviewed by naoto (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/18663#pullrequestreview-1984117426


More information about the core-libs-dev mailing list