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

SegmentAllocator:allocateArray(MemoryLayout, count) does not throw IAEx when count is -1

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P3
    • Resolution: Fixed
    • 19
    • 19
    • core-libs

    Backports

      Description

        The spec : https://download.java.net/java/early_access/jdk19/docs/api/java.base/java/lang/foreign/SegmentAllocator.html#allocate(java.lang.foreign.MemoryLayout)
        "Throws:
        IllegalArgumentException - if count < 0."

        Expecting the below code shall throw IAEx.

         try {
                    SegmentAllocator.implicitAllocator().allocateArray(ValueLayout.JAVA_BYTE, -1);
                }catch (IllegalArgumentException ex){
                    System.out.println("OK - Expected Exception ");
                }catch (Exception ex){
                    System.out.println("NOT OK - exception thrown is "+ex.getMessage());
                }

        Actual Result :
        java.lang.OutOfMemoryError: Cannot reserve 1152921504606846975 bytes...


        Note - For other negative numbers the implementation throws IAEx.

        Attachments

          Issue Links

            Activity

              People

                mcimadamore Maurizio Cimadamore
                kganapureddy Krushnareddy Ganapureddy
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: