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

system class loader can not find initial class of working program

    XMLWordPrintable

Details

    • sparc
    • solaris_2.5.1

    Description



      Name: szC45993 Date: 05/24/98



      The
      vm/constantpool/ClassInterf/ClassInterf021/ClassInterf02101/ClassInterf02101.html
      vm/constantpool/ClassInterf/ClassInterf023/ClassInterf02301/ClassInterf02301.html
      vm/constantpool/ClassInterf/ClassInterf025/ClassInterf02501/ClassInterf02501.html
      vm/constantpool/ClassInterf/ClassInterf028/ClassInterf02801/ClassInterf02801.html
      vm/constantpool/ClassInterf/ClassInterf029/ClassInterf02901/ClassInterf02901.html
      vm/constantpool/ClassInterf/ClassInterf030/ClassInterf03001/ClassInterf03001.html
      vm/constantpool/ClassInterf/ClassInterf032/ClassInterf03201/ClassInterf03201.html
      vm/constantpool/ClassInterf/ClassInterf033/ClassInterf03301/ClassInterf03301.html
      vm/constantpool/ClassInterf/ClassInterf037/ClassInterf03701/ClassInterf03701.html
      vm/constantpool/ClassInterf/ClassInterf040/ClassInterf04001/ClassInterf04001.html
      vm/constantpool/ClassInterf/ClassInterf044/ClassInterf04401/ClassInterf04401.html
      vm/constantpool/ClassInterf/ClassInterf045/ClassInterf04501/ClassInterf04501.html
      vm/constantpool/ClassInterf/ClassInterf046/ClassInterf04601/ClassInterf04601.html
      vm/constantpool/ClassInterf/ClassInterf057/ClassInterf05701/ClassInterf05701.html
      vm/constantpool/ClassInterf/ClassInterf056/ClassInterf05601/ClassInterf05601.html
      tests show
      that jdk1.2b4C erroneously uses non-system class loader for the loading
      of the initial class of java program (it contradicts to vm spec).
      Besides of that, may be as consequence of this,
      SYSTEM CLASS LOADER CAN NOT FIND INITIAL CLASS OF WORKING PROGRAM when system
      loader is used inside own class loader of this program.

      Short test placed below demonstrates the incorrect jvm behaviour:

      novo7% /export/ld14/java/dest/jdk1.2b4G/solaris/bin/javac ClassInterf02101.java
      novo7% /export/ld14/java/dest/jdk1.2b4G/solaris/bin/java -verify ClassInterf02101

      ERROR1: Class loader of initial class must be system class loader (i.e. the following must be true: getClassLoader() == null) but really class loader of initial class is sun.misc.Launcher$AppClassLoader@1903304a

      (((loadClass: ClassInterf02101


      findSystemClass correctly belongs to the system class loader (getClassLoader= null)

      (((findSystemClass: ClassInterf02101
      java.lang.ClassNotFoundException: ClassInterf02101

      ERROR3: System class loader (findSystemClass) used by user class loader has not found initial class of running java program.

      novo7%

      SOURCE:


      --------------------- ClassInterf02101.java
      import java.io.PrintStream;
      import java.util.*;

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

        public synchronized Class loadClass(String name, boolean resolve) {
      Class c = (Class) cache.get(name);

      /**/ ClassInterf02101.o.println(" (((loadClass: "+name);


      ClassInterf02101.o.println();
      try{
      if (findSystemClass("java/lang/Class").getClassLoader() == null) {
      ClassInterf02101.o.println();
      ClassInterf02101.o.println("findSystemClass correctly belongs to the system class loader (getClassLoader= "+findSystemClass("java/lang/Class").getClassLoader()+")");
      } else {
      ClassInterf02101.o.println("ERROR2: findSystemClass erroneously belongs to non-system class loader (getClassLoader= "+findSystemClass("java/lang/Class").getClassLoader()+")");
      }
      }
      catch (java.lang.Throwable e) {
      ClassInterf02101.o.println(e);
      };
      ClassInterf02101.o.println();
      if (c == null) {
      try{
      /**/ ClassInterf02101.o.println(" (((findSystemClass: "+name);
      c = findSystemClass(name);
      /**/ ClassInterf02101.o.println(" )))findSystemClass: "+name);
      }
      catch (java.lang.ClassNotFoundException e) {
      ClassInterf02101.o.println(" "+e);
      return null;
      };
      cache.put(name, c);
      return c;
      }

      if (resolve){
      /**/ ClassInterf02101.o.println(" (((resolveClass: "+c);
      resolveClass(c);
      /**/ ClassInterf02101.o.println(" )))resolveClass: "+c);
      }

      /**/ ClassInterf02101.o.println(" )))loadClass: "+name);
      return c;
        }

      }

      public class ClassInterf02101 {

        public static PrintStream o;

        public static int run(String argv[], PrintStream out) {
          try{
      myClassLoader mcl = new myClassLoader();

      o = out;

      if (ClassInterf02101.class.getClassLoader() != null) {
      out.println();
      out.println("ERROR1: Class loader of initial class must be system class loader (i.e. the following must be true: getClassLoader() == null) but really class loader of initial class is "+ClassInterf02101.class.getClassLoader());
      out.println();
      }
      try{
      if (mcl.loadClass("ClassInterf02101", true) == (Class) null) {
      out.println();
      out.println("ERROR3: System class loader (findSystemClass) used by user class loader has not found initial class of running java program.");
      out.println();
      return 2;
      }
      }
      catch (java.lang.Throwable e) {
      out.println(" "+e);
      return 2;
      };

      return 0;

          } catch (SecurityException e) {
      out.println(" "+e);
      out.println("Could not setup test.");
      return 0;
          }
        }

        public static void main(String argv[]) {
      System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
        }

      }
      ======================================================================

      Hook 5(hook5): test

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

      Attachments

        Issue Links

          Activity

            People

              apalanissunw Anand Palaniswamy (Inactive)
              zsssunw Zss Zss (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: