On Tue, 27 Aug 2024 16:51:21 GMT, Dean Long <dl...@openjdk.org> wrote:
>> Why? I think that would have a large flow on effect. And this length does >> fit in an int. > > The worse case is len == SIZE_MAX and therefore num_chars == SIZE_MAX, which > won't fit in an int. If we say this will never happen because current > callers never use sizes bigger than int, that makes the code fragile against > scenarios where a developer might add a new caller. (A whitebox test or > gtest could be written that makes the checked_cast fail.) If you try to accommodate arbitrary future use then every method in the VM would need to enforce every single precondition and invariant it expects "just in case" and that is not practical. Code can and does take advantage of the expected calling context, which here limits lengths to int (and typically < 64K). The checked_cast serves to catch such misuses in my opinion. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/20560#discussion_r1733539059