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

SegmentAllocator:allocate(java.lang.foreign.MemoryLayout,long) throws unstated exception

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 22
    • core-libs

      As per the spec - https://download.java.net/java/early_access/jdk22/docs/api/java.base/java/lang/foreign/SegmentAllocator.html#allocate(java.lang.foreign.MemoryLayout,long)
      Throws:
      IllegalArgumentException - if elementLayout.byteSize() * count overflows

      actually - java.lang.IndexOutOfBoundsException is thrown.


      Is it a typo in the spec?

      sample code

      ===
      private void test01() {
              SegmentAllocator segmentAllocator = SegmentAllocator.prefixAllocator(MemorySegment.ofArray(new byte[4]));
              try {
                  segmentAllocator.allocate(ValueLayout.JAVA_BYTE, 5);
              }catch (IllegalArgumentException ex){
                  System.out.println("Expected ");
              } catch (Throwable t){
                  System.out.println("actual is "+t);
              }
          }
      ===
      output:
      actual is java.lang.IndexOutOfBoundsException

            Unassigned Unassigned
            kganapureddy Krushnareddy Ganapureddy
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: