On Tue, 12 Dec 2023 11:05:44 GMT, Maurizio Cimadamore <[email protected]>
wrote:
>> This PR proposes to change the specification for some methods that take
>> `long` offsets so that they will throw an `IllegalArgumentException` rather
>> than an `IndexOutOfBoundsException` for negative values.
>>
>> The PR also proposes to fix a bug where the allocation size would overflow
>> and the specified exception was not thrown.
>
> src/java.base/share/classes/java/lang/foreign/SegmentAllocator.java line 737:
>
>> 735: private MemorySegment allocateNoInit(MemoryLayout layout, long
>> size) {
>> 736: long byteSize;
>> 737: try {
>
> I don't think we want this. While it is more correct, that would negatively
> affect performance. If there's an overflow, let it go negative, it will be
> caught anyway
True. But we will get the wrong type of exception.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17079#discussion_r1423876941