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

Class.arrayType() for a 255-d array throws undocumented IllegalArgumentException

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 19
    • core-libs
    • None
    • behavioral
    • low
    • Modify exceptional behavior in an undocumented and presumed rare case.
    • Java API
    • SE

      Summary

      Add explicit discussion of exceptional conditions to Class.arrayType.

      Problem

      The Class.arrayType method does not state how it handles exceptional conditions, such as exceeding the maximum supported array dimensions.

      Solution

      Add the needed @throws tag. The previous implementation threw llegalArgumentException, propagated from elsewhere; this change instead threads UnsupportedOperationException since the state of this isn't usually the basis for an llegalArgumentException.

      Specification

      diff --git a/src/java.base/share/classes/java/lang/Class.java b/src/java.base/share/classes/java/lang/Class.java
      index b8bf7de250e..137756c9176 100644
      --- a/src/java.base/share/classes/java/lang/Class.java
      +++ b/src/java.base/share/classes/java/lang/Class.java
      @@ -4435,7 +4435,12 @@ public final class Class<T> implements java.io.Serializable,
            * Returns a {@code Class} for an array type whose component type
            * is described by this {@linkplain Class}.
            *
      +     * @throws UnsupportedOperationException if this component type is {@linkplain
      +     *         Void#TYPE void} or if the number of dimensions of the resulting array
      +     *         type would exceed 255.
            * @return a {@code Class} describing the array type
      +     * @jvms 4.3.2 Field Descriptors
      +     * @jvms 4.4.1 The {@code CONSTANT_Class_info} Structure
            * @since 12
            */

            darcy Joe Darcy
            webbuggrp Webbug Group
            Alan Bateman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: