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

non-AbstractMethodError on preparing stage of Class Loader

XMLWordPrintable

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



      Name: szC45993 Date: 03/13/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 (3b), claims:

      "If a class that is not declared abstract has an abstract method, class resolution throws an AbstractMethodError."

      Meanwhile, undermentioned test gives the following result (jdk_1.0.2, jdk_1.1.1):
      -------------------------------------------------------------------------
      ...
      java.lang.InstantiationException: javasoft/sqe/tests/vm/constantpool/ClassInterf043/ClassInterf04301/Intrmdt
      ERROR2: None AbstractMethodError is rised if the following situation is descovered: non-abstract class has abstract method!
      ERROR1: Error must be rised on the preparing stage and before initializing stage!
      ...
      -------------------------------------------------------------------------

      So InstantiationException is rised instead of AbstractMethodError and, may be, this exception is rised on the initializing stage instead of the preparing stage as it's needed.

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

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

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

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

      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/ClassInterf04301/";
      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) {ClassInterf04301.o.println(e);return null;};
      str_2 = str_1.concat("/javasoft/sqe/tests/vm/constantpool/ClassInterf043/ClassInterf04301/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) {ClassInterf04301.o.println(e);return null;};
      str1 = str1.substring(str1.indexOf(":")+1);
      str_2 = str_1.concat("/javasoft/sqe/tests/vm/constantpool/ClassInterf043/ClassInterf04301/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) {ClassInterf04301.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 s3 = "ClassInterf04301";
      String s4 = "Runnable";
      String name1;


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

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

      return c;
        }

      }

      public class ClassInterf04301 {

        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("********ClassInterf04301.run*********");

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

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

      }
      catch (java.lang.AbstractMethodError e) {
      out.println(e);
      index1 = loadedname.indexOf("Intrmdt INITIALIZING begin");
      if (index1 != -1) {
      out.println("ERROR3: AbstractMethodError must be rised on the preparing stage and before initializing stage!");
      return 2;
      }
      return 0;
      }
      catch (java.lang.NoClassDefFoundError e) {
      out.println(e);
      }
      catch (java.lang.IllegalAccessException e) {
      out.println(e);
      }
      catch (java.lang.InstantiationException e) {
      out.println(e);
      };


      out.println("ERROR2: None AbstractMethodError is rised if the following situation is descovered: non-abstract class has abstract method!");
      index1 = loadedname.indexOf("Intrmdt INITIALIZING begin");
      if (index1 != -1) {
      out.println("ERROR1: Error must be rised on the preparing stage and before initializing stage!");
      }
      out.println("-----"+loadedname+"-----");
      return 2;

        }

        public static void main(String argv[]) {
      System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
        }
      }
      --------------------- Intrmdt.jasm
      package javasoft/sqe/tests/vm/constantpool/ClassInterf043/ClassInterf04301;

      public synchronized class Intrmdt
      implements java/lang/Runnable
      {
      // Compiled from Intrmdt.java
      // Compiler version 3.45;

      static Field str:"Ljava/lang/String;";

      public Method run:"()V"
      stack 2 locals 1
      {
      getstatic Field ClassInterf04301.o:"Ljava/io/PrintStream;";
      ldc String "********Intrmdt.run*********";
      invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/String;)V";
      return;
      }

      public abstract Method run:"()V";
      //!!!!!^^^^^^^^!!!!!!!!!!!!
      //!!!!!^^^^^^^^!!!!!!!!!!!!
      //!!!!!^^^^^^^^!!!!!!!!!!!!

      public Method <init>:"()V"
      stack 1 locals 1
      {
      aload_0;
      invokespecial Method java/lang/Object.<init>:"()V";
      return;
      }

      static Method <clinit>:"()V"
      stack 2 locals 0
      {
      getstatic Field ClassInterf04301.o:"Ljava/io/PrintStream;";
      ldc String " Intrmdt INITIALIZING begin";
      invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/String;)V";
      getstatic Field ClassInterf04301.loadedname:"Ljava/lang/String;";
      ldc String "Intrmdt INITIALIZING begin";
      invokevirtual Method java/lang/String.concat:"(Ljava/lang/String;)Ljava/lang/String;";
      putstatic Field ClassInterf04301.loadedname:"Ljava/lang/String;";
      ldc String "Class Intrmdt is linked";
      putstatic Field str:"Ljava/lang/String;";
      getstatic Field ClassInterf04301.loadedname:"Ljava/lang/String;";
      ldc String "Intrmdt INITIALIZING end";
      invokevirtual Method java/lang/String.concat:"(Ljava/lang/String;)Ljava/lang/String;";
      putstatic Field ClassInterf04301.loadedname:"Ljava/lang/String;";
      getstatic Field ClassInterf04301.loadedname:"Ljava/lang/String;";
      getstatic Field str:"Ljava/lang/String;";
      invokevirtual Method java/lang/String.concat:"(Ljava/lang/String;)Ljava/lang/String;";
      putstatic Field ClassInterf04301.loadedname:"Ljava/lang/String;";
      getstatic Field ClassInterf04301.o:"Ljava/io/PrintStream;";
      ldc String " Intrmdt INITIALIZING end";
      invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/String;)V";
      return;
      }

      } // end Class Intrmdt
      ---------------------

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

            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: