RFR: 8321387: SegmentAllocator:allocateFrom(AddressLayout, MemorySegment) does not throw stated UnsupportedOperationException

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Dec 6 14:05:37 UTC 2023


On Wed, 6 Dec 2023 13:52:37 GMT, Per Minborg <pminborg at openjdk.org> wrote:

> This PR proposes to change the exception type for exceptions thrown for certain methods with a parameter of type `MemorySegment` when it is `MemorySegment::isReadOnly`. Previously an `UnsupportedOperationException` was specified but in some cases, in reality, an `IllegalArgumentException` was thrown. 
> 
> The principle used in this PR is that operations acting on an MS where the MS is `this` should throw an `UnsupportedOperationException` whereas in cases where the MS is a *parameter* an `IllegalArgumentException` should be thrown.
> 
> It should be noted that this PR retains the previous behavior for MS VarHandle access (even though the MS is a parameter to the accessor methods, the first parameter can be said to represent `this`).

src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java line 363:

> 361: 
> 362:     public enum AccessConstraint {
> 363:         READ_ONLY, ON_WRITE_UOE, ON_WRITE_IAE

I think the names are a bit confusing. Perhaps having NONE instead of READ_ONLY would be better.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16993#discussion_r1417378162


More information about the core-libs-dev mailing list