On Tue, 1 Sep 2026 07:45:22 GMT, Per Minborg <[email protected]> wrote:

>> This PR proposes to introduce checks for multiplication overflow in 
>> `SequenceLayoutImpl`. 
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Per Minborg has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Document exception and add tests

src/java.base/share/classes/java/lang/foreign/SequenceLayout.java line 117:

> 115:      *         sequence layout
> 116:      * @throws ArithmeticException if the flattened element count cannot 
> be represented
> 117:      *                             as a {@code long}

`ArithmeticException` doesn't seem like the right exception type here. I think 
`UnsupportedOperationException` would be better.

Also, 'flattened element count' sounds like a new term (especially in this 
context). I suggest rewording this to  'element count of the flattened 
representation of this sequence'.

Same for `flatten` on both.

src/java.base/share/classes/jdk/internal/foreign/layout/SequenceLayoutImpl.java 
line 180:

> 178:             hasZeroCount |= elemCount == 0;
> 179:             elemLayout = elemSeq.elementLayout();
> 180:         }

This deserves a comment I think. Something like: 'do a separate pass to figure 
out if the final element count will be zero, to prevent throwing on overflow in 
that case'.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/32191#discussion_r3903323259
PR Review Comment: https://git.openjdk.org/jdk/pull/32191#discussion_r3903331648

Reply via email to