On Tue, 6 Jan 2026 10:47:04 GMT, David Beaumont <[email protected]> wrote:
>> Fair points. This is just moved code, but IOOBE is clearly not the right >> choice here. > > In fact, taking a more holistic view, the size check is already done by the > caller, so there's some nice simplification possible here. You *do* need a negative check when using long because of underflow. If longValue is 0xFFFFFFFF00000001 (negative, invalid) then '(int) longValue' is 1 (positive, valid). https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.3 Or you could use a different style of check: int intValue = (int) longValue; if (intValue != longValue) { throw ... } ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/29043#discussion_r2664543524
