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

byteArrayViewVarHandle should throw ArrayIndexOutOfBoundsException

    XMLWordPrintable

Details

    • Enhancement
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • None
    • 17
    • core-libs
    • None

    Description

      To ease portability, array view VarHandles could be adapted to throw AIOOBE rather than IOOBE:

      VarHandle VH = MethodHandles.byteArrayViewVarHandle(int[].class,
                      ByteOrder.LITTLE_ENDIAN);
      byte[] bytes = new byte[16];
      VH.get(bytes, 15);

      Current:
      // Exception java.lang.IndexOutOfBoundsException: Index 15 out of bounds for length 13

      Expected:
      // Exception java.lang.ArrayIndexOutOfBoundsException: Index 15 out of bounds for length 13

      Code changes are straightforward: Pass Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new) to Preconditions.checkIndex in ArrayHandle::index(byte[] ba, int index) in src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template

      Attachments

        Issue Links

          Activity

            People

              redestad Claes Redestad
              redestad Claes Redestad
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: