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

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

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      When we invoke java.lang.Class.arrayType() for a 255-dimension array, it unexpectedly throws an IllegalArgumentException, which is not documented.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the given Java code.

      ACTUAL -
      It prints the following message to stderr:
      Unexpected java.lang.IllegalArgumentException
      at java.base/java.lang.reflect.Array.newArray(Native Method)
      at java.base/java.lang.reflect.Array.newInstance(Array.java:78)
      at java.base/java.lang.Class.arrayType(Class.java:4360)
      at com.yuantj.test.Main.main(Main.java:10)

      ---------- BEGIN SOURCE ----------
      package com.yuantj.test;

      public final class Main {
          public static void main(String[] args) {
              Class<?> cls = Object.class;
              for (int i = 0; i < 255; ++i) {
                  cls = cls.arrayType();
              }
              try {
                  System.out.println(cls.arrayType());
              } catch (IllegalArgumentException e) {
                  System.err.print("Unexpected ");
                  e.printStackTrace();
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Make it return null, throw an IllegalStateException, or document it.

      FREQUENCY : always


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

              Created:
              Updated:
              Resolved: