There are a couple of places that contain technical typos in the FFM guides:
1. In here https://docs.oracle.com/en/java/javase/23/core/slicing-allocators-and-slicing-memory-segments.html#GUID-1BA7C6C3-2090-4202-8EC9-330EAE8BBB9B :
a) The phrase
You can also obtain a slice of a memory segment of any location within a memory segment with the method MethodSegment::asSlice
makes a reference to a class that doesn't exist in the public API. Instead it should be MemorySegment::asSlice .
b) There is a small typo in this phrase: It then uses a slicing allocator by calling SegmentAllocator.slicingAllocator(MemorySgement).
The argument should be MemorySegment, not MemorySgement.
2. In https://docs.oracle.com/en/java/javase/23/core/upcalls-passing-java-code-function-pointer-foreign-function.html#GUID-908061BA-DC97-4524-A390-8FCEF7C5978F
a) The example uses allocateArray method that doesn't exist anymore for SegmentAllocator and hence unavailable for Arena. As a result, the example doesn't compile. The faulty code:
// Allocate off-heap memory and store unsortedArray in it
MemorySegment array = arena.allocateArray(ValueLayout.JAVA_INT, unsortedArray);
Instead of arena.allocateArray, the example should use arena.allocateFrom (the allocateFrom method that Arena gets by extending SegmentAllocator)
3. In https://docs.oracle.com/en/java/javase/23/core/checking-native-errors-using-errno.html :
a) The invokeLog method will not compile because it calls for getUtf8String method on a MemorySegment and the method is not available anymore in the API.
// Convert errno code to a string message:
String errrorString = ((MemorySegment) strerror.invokeExact(errno))
.reinterpret(Long.MAX_VALUE).getUtf8String(0);
To fix this, the code should call for getString:
// Convert errno code to a string message:
String errrorString = ((MemorySegment) strerror.invokeExact(errno))
.reinterpret(Long.MAX_VALUE).getString(0);
b) Once the code compiles, at runtime will throw java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(VarHandle,MemorySegment,long)int to (VarHandle,MemorySegment)int.
// Get more information by consulting the value of errno:
int errno = (int) errnoHandle.get(capturedState);
That happens because the capturedState is missing the base offset :
// Get more information by consulting the value of errno:
int errno = (int) errnoHandle.get(capturedState, 0);
4. There is a small typo in the first example from
https://docs.oracle.com/en/java/javase/23/core/foreign-functions-that-return-pointers.html#GUID-908061BA-DC97-4524-A390-8FCEF7C5978F. Search for Localte.
5. In https://docs.oracle.com/en/java/javase/23/core/restricted-methods.html the parenthesis opened to exemplify - (for example - is not closed:
Once you have an address layout with a given target layout, you can use it in a dereference operation (for example, MemorySegment.get(AddressLayout, long) to resize the segment being read, which is unsafe.
1. In here https://docs.oracle.com/en/java/javase/23/core/slicing-allocators-and-slicing-memory-segments.html#GUID-1BA7C6C3-2090-4202-8EC9-330EAE8BBB9B :
a) The phrase
You can also obtain a slice of a memory segment of any location within a memory segment with the method MethodSegment::asSlice
makes a reference to a class that doesn't exist in the public API. Instead it should be MemorySegment::asSlice .
b) There is a small typo in this phrase: It then uses a slicing allocator by calling SegmentAllocator.slicingAllocator(MemorySgement).
The argument should be MemorySegment, not MemorySgement.
2. In https://docs.oracle.com/en/java/javase/23/core/upcalls-passing-java-code-function-pointer-foreign-function.html#GUID-908061BA-DC97-4524-A390-8FCEF7C5978F
a) The example uses allocateArray method that doesn't exist anymore for SegmentAllocator and hence unavailable for Arena. As a result, the example doesn't compile. The faulty code:
// Allocate off-heap memory and store unsortedArray in it
MemorySegment array = arena.allocateArray(ValueLayout.JAVA_INT, unsortedArray);
Instead of arena.allocateArray, the example should use arena.allocateFrom (the allocateFrom method that Arena gets by extending SegmentAllocator)
3. In https://docs.oracle.com/en/java/javase/23/core/checking-native-errors-using-errno.html :
a) The invokeLog method will not compile because it calls for getUtf8String method on a MemorySegment and the method is not available anymore in the API.
// Convert errno code to a string message:
String errrorString = ((MemorySegment) strerror.invokeExact(errno))
.reinterpret(Long.MAX_VALUE).getUtf8String(0);
To fix this, the code should call for getString:
// Convert errno code to a string message:
String errrorString = ((MemorySegment) strerror.invokeExact(errno))
.reinterpret(Long.MAX_VALUE).getString(0);
b) Once the code compiles, at runtime will throw java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(VarHandle,MemorySegment,long)int to (VarHandle,MemorySegment)int.
// Get more information by consulting the value of errno:
int errno = (int) errnoHandle.get(capturedState);
That happens because the capturedState is missing the base offset :
// Get more information by consulting the value of errno:
int errno = (int) errnoHandle.get(capturedState, 0);
4. There is a small typo in the first example from
https://docs.oracle.com/en/java/javase/23/core/foreign-functions-that-return-pointers.html#GUID-908061BA-DC97-4524-A390-8FCEF7C5978F. Search for Localte.
5. In https://docs.oracle.com/en/java/javase/23/core/restricted-methods.html the parenthesis opened to exemplify - (for example - is not closed:
Once you have an address layout with a given target layout, you can use it in a dereference operation (for example, MemorySegment.get(AddressLayout, long) to resize the segment being read, which is unsafe.