byteArrayViewVarHandle should throw ArrayIndexOutOfBoundsException

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P4
    • 17
    • Affects Version/s: None
    • Component/s: core-libs
    • None

      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

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

              Created:
              Updated:
              Resolved: