On Tue, 12 Dec 2023 10:02:00 GMT, Per Minborg <pminb...@openjdk.org> 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

src/java.base/share/classes/jdk/internal/foreign/layout/AbstractLayout.java 
line 156:

> 154:         Utils.checkNonNegative(offset, "offset");
> 155:         Utils.checkNonNegative(index, "index");
> 156:         if (offset < 0) {

Duplicate check?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17079#discussion_r1423834990
PR Review Comment: https://git.openjdk.org/jdk/pull/17079#discussion_r1423835592

Reply via email to