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

ExceptionInInitializerError is not rised under initializer interruption

XMLWordPrintable

    • 1.2alpha2
    • sparc
    • solaris_2.5
    • Not verified



      Name: szC45993 Date: 03/15/97



      The Java Virtual Machine, chapter 5 Constant Pool Resolution,
      section 5.1.2 Current Class or Interface Loaded by Class Loader, claims:

      "If the class file is successfully verified, the class or interface is then prepared (step 3b of $5.1.1) and initialized (step 4 of $5.1.1)."

      and section 5.1.1 Current Class or Interface Not Loaded by Class Loader (4), claims:

      "If an initializer completes abruptly by throwing some exception E, and if the class of E is not Error or one of its subclasses, then a new instance of the class ExceptionInInitializerError, with E as the argument, is created and used in place of E."

      Meanwhile, undermentioned test gives the following result (jdk_1.0.2):
      -------------------------------------------------------------------------
      ...
              Intrmdt INITIALIZING begin
      ( loadClass: java.lang.String true
      ( findSystemClass: java.lang.String
      ) findSystemClass: java.lang.String
      ( resolveClass: java.lang.String
      ) resolveClass: java.lang.String
      ) loadClass: java.lang.String
      java.lang.ArithmeticException: / by zero
      at javasoft.sqe.tests.vm.constantpool.ClassInterf043.ClassInterf04302.Intrmdt.<clinit>(Intrmdt.java:20)
      at java.lang.ClassLoader.resolveClass(ClassLoader.java)
      at javasoft.sqe.tests.vm.constantpool.ClassInterf043.ClassInterf04302.myClassLoader.loadClass(ClassInterf04302.java:138)
      at javasoft.sqe.tests.vm.constantpool.ClassInterf043.ClassInterf04302.ClassInterf04302.run(ClassInterf04302.java:175)
      at javasoft.sqe.tests.vm.constantpool.ClassInterf043.ClassInterf04302.ClassInterf04302.main(ClassInterf04302.java:237)
      ) resolveClass: javasoft.sqe.tests.vm.constantpool.ClassInterf043.ClassInterf04302.Intrmdt
      ) loadClass: javasoft.sqe.tests.vm.constantpool.ClassInterf043.ClassInterf04302.Intrmdt
      ( loadClass: java.lang.Object true
      ( resolveClass: java.lang.Object
      ) resolveClass: java.lang.Object
      ) loadClass: java.lang.Object
      ********Intrmdt.run*********
      0
      ERROR3: Error or Exception is not rised when the following situation is descovered: an initializer completes abruptly by throwing some exception E, and the class E is not Error or one of its subclasses!
      -------------------------------------------------------------------------

      See also 4013899 and 4038613 for a class "not loaded by Class Loader", because of the error reasons in both cases may be equal for a jvm release.


      Attention, please, ClassInterf04302.jasm was really used instead of ClassInterf04302.java because of ExceptionInInitializerError was the unknown Error for jdk_1.0.2 javac.

      --------------------- ClassInterf04302.java
      //File: @(#)ClassInterf04302.java 1.1 97/03/03
      //Copyright 03/03/97 Sun Microsystems, Inc. All Rights Reserved

      package javasoft.sqe.tests.vm.constantpool.ClassInterf043.ClassInterf04302;

      import java.io.PrintStream;
      import java.io.*;
      import java.lang.*;
      import java.util.*;
      import java.awt.*;

      interface Inter {
          int intrmdtprc(PrintStream out);
      }

      class myClassLoader extends java.lang.ClassLoader {
        Hashtable cache = new Hashtable();

        private byte loadClassData(String name)[] {
      String str_1,str_2,str1 = "",str2 = "/javasoft/sqe/tests/vm/constantpool/ClassInterf043/ClassInterf04302/";
      File fl1;
      FileInputStream fl3;
      byte bt[];
      int length;
      int index = 0;
      Properties prpr = System.getProperties();

      str_1 = prpr.getProperty("java.class.path");
      str2 = str2.concat(name);
      str2 = str2.concat(".class");
      str1 = str1.concat(str_1.substring(str_1.indexOf(":")+1));
      try{
      index = str_1.indexOf(":");
      str_1 = str_1.substring(0,index);
      } catch (Exception e) {ClassInterf04302.o.println(e);return null;};
      str_2 = str_1.concat("/javasoft/sqe/tests/vm/constantpool/ClassInterf043/ClassInterf04302/Intrmdt.class");
      str_1 = str_1.concat(str2);

      while (true) {
      fl1 = new File(str_2);
      if (fl1.isFile()) {
      break;
      } else {
      str_1 = "";
      try{
      index = str1.indexOf(":");
      str_1 = str_1.concat(str1.substring(0,index));
      } catch (Exception e) {ClassInterf04302.o.println(e);return null;};
      str1 = str1.substring(str1.indexOf(":")+1);
      str_2 = str_1.concat("/javasoft/sqe/tests/vm/constantpool/ClassInterf043/ClassInterf04302/Intrmdt.class");
      str_1 = str_1.concat(str2);
      }
      }

      try{
      fl3 = new FileInputStream(str_1);
      length = fl3.available();
      bt = new byte[length];
      fl3.read(bt);
      fl3.close();


      } catch (java.io.IOException e) {ClassInterf04302.o.println(e);return null;};

      return bt;

        }

        public synchronized Class loadClass(String name, boolean resolve) {
      Class c = (Class) cache.get(name);
      String s1 = "Intrmdt";
      String s2 = "clss";
      String s3 = "ClassInterf04302";
      String s4 = "Runnable";
      String s5 = "suclss";
      String name1;

      ClassInterf04302.o.println("( loadClass: "+name+" "+resolve);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#");
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat(name);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat(" ");
      if (resolve) {
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("true");
      } else {
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("false");
      }
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#:loadClass enter#");

      if (name.indexOf(s1) != -1) {
      name1 = s1;
      } else if (name.indexOf(s5) != -1) {
      name1 = s5;
      } else if (name.indexOf(s2) != -1) {
      name1 = s2;
      } else {
      name1 = name;
      }

      if (name1.indexOf(".") != -1) {
      if (c == null) {
      try{
      ClassInterf04302.o.println("( findSystemClass: "+name);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#");
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat(name);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#:findSystemClass enter#");
      c = findSystemClass(name1);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#");
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat(name);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#:findSystemClass exit#");
      ClassInterf04302.o.println(") findSystemClass: "+name);
      }
      catch (java.lang.ClassNotFoundException e) {
      ClassInterf04302.o.println(e);
      return null;
      };
      cache.put(name, c);
      }
      } else {
      if (c == null) {
      byte data[] = loadClassData(name1);
      ClassInterf04302.o.println("( defineClass: "+name);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#");
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat(name);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#:defineClass enter#");
      c = defineClass(data,0,data.length);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#");
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat(name);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#:defineClass exit#");
      ClassInterf04302.o.println(") defineClass: "+name);
      cache.put(name, c);
      }
      }
      if (resolve) {
      ClassInterf04302.o.println("( resolveClass: "+name);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#");
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat(name);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#:resolveClass enter#");
      resolveClass(c);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#");
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat(name);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#:resolveClass exit#");
      ClassInterf04302.o.println(") resolveClass: "+name);
      }

      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#");
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat(name);
      ClassInterf04302.loadedname = ClassInterf04302.loadedname.concat("#:loadClass exit#");
      ClassInterf04302.o.println(") loadClass: "+name);
      return c;
        }

      }

      public class ClassInterf04302 {

        public static String loadedname = "";
        public static String strnm = "";
        public static PrintStream o;

        public static int run(String argv[], PrintStream out) {
      myClassLoader mcl = new myClassLoader();
      Class cl2 = null;
      Runnable r;
      int index1;
      int index2;
      int flg = 2;
      String str = "";

      o = out;

      try{

      out.println("********ClassInterf04302.run*********");

      cl2 = mcl.loadClass("javasoft.sqe.tests.vm.constantpool.ClassInterf043.ClassInterf04302.Intrmdt", true);

      r = (Runnable) cl2.newInstance();
      r.run();

      }
      catch (java.lang.ExceptionInInitializerError e) {
      // catch (java.lang.ArithmeticException e) {
      out.println("********111111111111111111*********");
      out.println(e);
      index1 = loadedname.indexOf("Intrmdt INITIALIZING begin");
      index2 = loadedname.indexOf("Intrmdt INITIALIZING end");
      if (index1 == -1 || index2 != -1) {
      out.println("ERROR1: ExceptionInInitializerError must be rised on the initializing stage!");
      return 2;
      }
      return 0;
      }
      catch (java.lang.NoClassDefFoundError e) {
      out.println("********222222222222222222*********");
      out.println(e);
      flg = 1;
      }
      catch (java.lang.IllegalAccessException e) {
      out.println("********333333333333333333*********");
      out.println(e);
      flg = 1;
      }
      catch (java.lang.InstantiationException e) {
      out.println("********444444444444444444*********");
      out.println(e);
      flg = 1;
      }
      catch (java.lang.Exception e) {
      out.println("********555555555555555555*********");
      out.println(e);
      flg = 1;
      }
      catch (java.lang.Error e) {
      out.println("********666666666666666666*********");
      out.println(e);
      flg = 1;
      };


      if (flg == 1) {
      out.println("ERROR2: None ExceptionInInitializerError is rised if the following situation is descovered: an initializer completes abruptly by throwing some exception E, and the class E is not Error or one of its subclasses!");
      } else {
      out.println("ERROR3: Error or Exception is not rised when the following situation is descovered: an initializer completes abruptly by throwing some exception E, and the class E is not Error or one of its subclasses!");
      return 2;
      }
      index1 = loadedname.indexOf("Intrmdt INITIALIZING begin");
      index2 = loadedname.indexOf("Intrmdt INITIALIZING end");
      if (index1 == -1 || index2 != -1) {
      out.println("ERROR4: Error or Exception must be rised on the initializing stage!");
      }
      out.println("-----"+loadedname+"-----");
      return 2;

        }

        public static void main(String argv[]) {
      System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
        }
      }
      --------------------- Intrmdt.jasm
      //File: @(#)Intrmdt.java 1.1 97/03/03
      //Copyright 03/03/97 Sun Microsystems, Inc. All Rights Reserved

      package javasoft.sqe.tests.vm.constantpool.ClassInterf043.ClassInterf04302;

      import java.io.PrintStream;
      import java.lang.*;

      public class Intrmdt implements Runnable{

      static int i1 = 1;
      static int i2 = 2;
      static int i3 = 3;
      static int i;

      static {
       ClassInterf04302.o.println(" Intrmdt INITIALIZING begin");
       ClassInterf04302.loadedname = (ClassInterf04302.loadedname).concat("Intrmdt INITIALIZING begin");

      i = 1 / (i3 - (i1 + i2)); //java.lang.ArithmeticException: / by zero

       ClassInterf04302.loadedname = (ClassInterf04302.loadedname).concat("Intrmdt INITIALIZING end");
       ClassInterf04302.o.println(" Intrmdt INITIALIZING end");
      }

        public void run() {
      ClassInterf04302.o.println("********Intrmdt.run*********");
      ClassInterf04302.o.println(i);
        }

      }
      ---------------------

      ======================================================================

            sliangsunw Sheng Liang (Inactive)
            zsssunw Zss Zss (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: