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

byteArrayViewVarHandle should throw ArrayIndexOutOfBoundsException

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 17
    • None
    • 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

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

              Created:
              Updated:
              Resolved: