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

Class.forName method throws an exception when trying to create an array with 256 dimensions

XMLWordPrintable

    • x86_64
    • linux

      ADDITIONAL SYSTEM INFORMATION :
      java version "1.8.0_151"
      Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      Accordingly to Javadoc (https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#forName-java.lang.String-) Class.forName method "Returns the Class object associated with the class or interface with the given string name". However, an exception is thrown when executing the following program:

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile above program
      2. Run it using Oracle HotSpot java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      class [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[Ljava.lang.String;
      ACTUAL -
      java.lang.ClassNotFoundException: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[Ljava/lang/String;
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:264)
      at A.main(A.java:11)

      ---------- BEGIN SOURCE ----------
      public class A {
          public static void main(String[] args) {
              StringBuilder sb = new StringBuilder();
              for (int i = 0; i < 256; i++) {
                  sb.append('[');
              }
              sb.append("Ljava.lang.String;");
              String name = sb.toString();
              Class<?> c;
              try {
                  c = Class.forName(name);
                  System.err.println(c);
              } catch (ClassNotFoundException e) {
                  e.printStackTrace();
              }
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            dkejriwal Deepak Kejriwal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: