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

XMLWordPrintable

    • Type: Bug
    • Resolution: Not an Issue
    • Priority: P3
    • None
    • Affects Version/s: 22
    • Component/s: 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

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

              Created:
              Updated:
              Resolved: