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

byteArrayViewVarHandle should throw ArrayIndexOutOfBoundsException

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 17
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      Hide
      This specialize the exception thrown from a more generic type to a more specialized type, which means most code written to expect IndexOutOfBoundsException should work as long as not doing exact class matching (e.getClass() == IndexOutOfBoundsException.class)
      Show
      This specialize the exception thrown from a more generic type to a more specialized type, which means most code written to expect IndexOutOfBoundsException should work as long as not doing exact class matching (e.getClass() == IndexOutOfBoundsException.class)
    • Interface Kind:
      Java API

      Description

      Summary

      Change so that out-of-bounds invocations of MethodHandles.byteArrayViewVarHandle throw ArrayIndexOutOfBoundsException rather than the more generic IndexOutOfBoundsException.

      Problem

      Code doing array operations in a way such that using MethodHandles.byteArrayViewVarHandle would be a good fit will currently have to accept that the specific AIOOBE thrown natively on out-of-bounds errors on arrays is replaced by the more generic IOOBE. This might be a challenge for picking up such VarHandles due creating a subtle behavioral mismatch, and adapting the code to throw the specific and more naturally fitting AIOOBE would ease migration.

      Solution

      Change the implementation internally so that AIOOBE is thrown when accessing an out-of-bounds index of a byte array via a MethodHandles.byteArrayViewVarHandle.

      Specification

      The specification of MethodHandles.byteArrayViewVarHandle is updated to specify that ArrayIndexOutOfBoundsException will be thrown:

           * <p>
           * Access of bytes at a given index will result in an
           * {@code ArrayIndexOutOfBoundsException} if the index is less than {@code 0}
           * or greater than the {@code byte[]} array length minus the size (in bytes)
           * of {@code T}.
           * <p>

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                redestad Claes Redestad
                Reporter:
                redestad Claes Redestad
                Reviewed By:
                Jorn Vernee, Paul Sandoz
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: