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

byteArrayViewVarHandle should throw ArrayIndexOutOfBoundsException

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 17
    • Component/s: core-libs
    • Labels:
      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

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

                Dates

                Created:
                Updated:
                Resolved: