JDK-8313228 : JEP442 - SegmentAllocator:allocateUtf8String(String str) spec mismatches to behavior
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.foreign
  • Affected Version: 21
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2023-07-27
  • Updated: 2023-08-10
  • Resolved: 2023-08-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21
21Resolved
Related Reports
Duplicate :  
Relates :  
Description
https://download.java.net/java/early_access/jdk21/docs/api/java.base/java/lang/foreign/SegmentAllocator.html#allocateUtf8String(java.lang.String)

Spec mentions that - "Returns:
a new native segment containing the converted C string."

But this looks not true for all types of SegmentAlloctor's.

For example :

===
SegmentAllocator segmentAllocator1 =  SegmentAllocator.prefixAllocator(MemorySegment.ofArray(new int[16]));
        MemorySegment memorySegment = segmentAllocator1.allocateUtf8String(strVal);
        System.out.println(memorySegment.isNative());
===

The spec needs to be updated to align with the behavior.


Comments
Tests in question: api/java_lang/foreign/SegmentAllocator/AllocateUtf8String.html[test_allocateUtf8String] api/java_lang/foreign/SegmentAllocator/AllocateUtf8String.html[test_allocateUtf8String_nullChar]
10-08-2023

The spec was not updated to reflect the desired change in the implementation. There is a JDK spec bug JDK-8298095. Based on the current state we can not use or develop tests based on the spec defect. Hence this is not a tck-red bug. When the spec if fixed in JDK 22 we will return the tests to the JCK product.
10-08-2023

This will be fixed via https://github.com/openjdk/jdk/pull/14997/files
31-07-2023

True, SegmentAllocator should not assume that returned segments are native.
27-07-2023