Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8321387

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 22
    • 22
    • core-libs

    Backports

      Description

        As per the spec-
        https://download.java.net/java/early_access/jdk22/docs/api/java.base/java/lang/foreign/SegmentAllocator.html#allocateFrom(java.lang.foreign.AddressLayout,java.lang.foreign.MemorySegment)

        when the supplied MemorySegment is not 'native' then this method supposed to throw "UnsupportedOperationException" but actually it throws java.lang.IllegalArgumentException: Heap segment not allowed:

        Sample code
        ====
         private void test01() {
                SegmentAllocator segmentAllocator = SegmentAllocator.prefixAllocator(Arena.ofAuto().allocate(1024));
                MemorySegment memorySegment = MemorySegment.ofArray(new int[10]);
                System.out.println("memorySegment is Native " + memorySegment.isNative());
                try {
                    segmentAllocator.allocateFrom(ValueLayout.ADDRESS.withName("test"), memorySegment);
                } catch (Exception ex) {
                    System.out.println("The ex is " + ex);
                }
            }
        =====

        Attachments

          Issue Links

            Activity

              People

                pminborg Per-Ake Minborg
                kganapureddy Krushnareddy Ganapureddy
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: