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

Class.arrayType should not throw IllegalArgumentException

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • core-libs
    • None
    • behavioral
    • low
    • Consumers of `Class.arrayType()` that expect an (unspecified) `IllegalArgumentExeption` to be thrown if the array rank exceeds 255 would break.
    • Java API
    • SE

      Summary

      Change the specification of java.lang.Class::arrayType() and java.lang.invoke.TypeDescriptor.OfField::arrayType() to throw an IllegalStateException if the array rank would exceed 255.

      Problem

      Currently Class::arrayType() throws an unspecified IllegalArgumentException, which is not appropriate for methods that don't take an argument. This should also be reflected in the documentation of TypeDescriptor.OfField::arrayType().

      Solution

      Change the specification of java.lang.Class::arrayType() and java.lang.invoke.TypeDescriptor.OfField::arrayType() to throw an IllegalStateException if the array rank would exceed 255.
      This matches the other implementation of java.lang.invoke.TypeDescriptor.OfField: java.lang.constant.ClassDesc.

      The behavior of Class::arrayType() changes, as it will now throw a different Exception in the error case.

      Specification

      java.lang.Class::arrayType():

        /**
         * Returns a {@code Class} for an array type whose component type
         * is described by this {@linkplain Class}.
         *
         * @return a {@code Class} describing the array type
      +  * @throws IllegalStateException if the resulting {@code Class} would have an array rank of greater than 255
         * @since 12
         */

      java.lang.invoke.TypeDescriptor.OfField::arrayType():

        /**
         * Return a descriptor for the array type whose component type is described by this
         * descriptor
      +  * @throws IllegalStateException if the resulting {@code TypeDescriptor.OfField} would have an array rank of greater than 255
         * @return the descriptor for the array type
         */

            jkuhn Johannes Kuhn
            jkuhn Johannes Kuhn
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: