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

(1.1) Calling newInstance on Class itself crashes VM

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.1.8
    • hotspot
    • x86
    • windows_nt



      Name: skT88420 Date: 05/06/99


      /* Compile and run
      The first direct call of newInstance throws the proper exception
      because obviously you cant create a class this way.

      However the second indirect call via invoke crashes the vm when
      the returned object is accessed.

      This must hold the record for the shortest code to crash the VM
      */

      import java.lang.Class;
      import java.lang.reflect.*;

      public class Newinstance {
      public static void main(String[] args) {
      Class[] methArgs = {};
      Class c = null;
      try {
      c = Class.forName("java.lang.Class");
      Object o = c.newInstance();
      if (o != null)
      // Throws IllegalAccessException which is ok
      o.toString();
      }
      catch (Throwable e) {
      System.out.println("Proper Exception");
      e.printStackTrace();
      }
      try {

      Method m = c.getMethod("newInstance", methArgs);
      Object o = m.invoke(c,null);
      if (o != null)
      // Now the VM crashes jdk 1.1.8 rc1
      System.out.println("Now the VM crashes");
      System.out.println("Object = " + o.toString());
      }
      catch (Throwable e) {
      System.out.println("Exception does not occur");
      e.printStackTrace();
      }
      }

      }
      (Review ID: 57896)
      ======================================================================

            apalanissunw Anand Palaniswamy (Inactive)
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: