-
CSR
-
Resolution: Approved
-
P3
-
None
-
behavioral
-
minimal
-
This change aligns the javadoc of the `MemoryLayout::offsetHandle` (and other) methods with what the implementation did all along. As such, this change doesn't affect behavior of existing programs.
-
Java API
-
SE
Summary
The specification for MemoryLayout::offsetHandle
doesn't specify under which circumstances the returned MethodHandle
can throw IndexOutOfBoundException
.
Problem
Consider this layout:
MemoryLayout SEQ = MemoryLayout.sequenceLayout(5,
MemoryLayout.sequenceLayout(10, JAVA_INT));
And the corresponding offset handle:
MethodHandle offsetHandle = SEQ.offsetHandle(PathElement.sequenceLayout(), PathElement.sequenceLayout());
The resulting method handle takes two additional long
indices. The implementation checks that the dynamically provided indices conform to the bound available at construction:
- the first index must be < 5
- the second must be < 10
If any of the above checks fail, then IndexOutOfBoundException
is thrown.
However, the javadoc for MemoryLayout::byteOffsetHandle
doesn't specify this behavior. This is made worse by the fact that the implementation of other methods in the MemoryLayout API is specified in terms of MemoryLayout::byteOffsetHandle
:
sliceHandle
varHandle
arrayElementVarHandle
Solution
MemoryLayout::byteOffsetHandle
, and all the methods derived from it should clearly specify what index checks are applied to the method handles/var handles they return.
Specification
- csr of
-
JDK-8332003 Clarify javadoc for MemoryLayout::offsetHandle
-
- Resolved
-