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

java.lang.Class.forName() throws unspecified exceptions

XMLWordPrintable

    • sparc
    • solaris_2.4



      Name: akC45999 Date: 03/13/98



      The description of java.lang.Class.forName() reads:

      Given the fully-qualified name for a class or interface, this method attempts
      to locate, load and link the class. If it succeeds, returns the Class object
      representing the class. If it fails, the method throws a ClassNotFoundException.

      But in the JDK1.1 ... JDK1.2 the method throws various subclasses of LinkageError
      instead, depending on actual reason of linkage failure. Though such behavior
      may be considered more useful than the specified, it violates the specification
      and must be fixed, unless the specification changes.

      See also RFE 4118967 on possible specification change, and "reverse" bug
      4112525 (runtime throws ClassNotFoundException while a LinkageError must be thrown).

      The following test illustrates the bug.

      Save 3 files in a working directory and run the script "runtest":

      novo64% which java
      /export/ld14/java/dest/jdk1.1.4/solaris/bin/java
      novo64% runtest
      javac ClassForName.java
      jasm aClass.jasm
      exception while loading test: java.lang.VerifyError: aClass

      novo64% which java
      /export/ld14/java/dest/jdk1.1.6/solaris/bin/java
      novo64% java -verify ClassForName
      exception while loading test: java.lang.VerifyError

      novo64% which java
      /export/ld14/java/dest/jdk1.2/solaris/bin/java
      java -verify ClassForName
      exception while loading test: java.lang.VerifyError: (class: aClass, method: <clinit> signature: ()V) Illegal local variable number

      ============================================================ ClassForName.java
      import java.io.PrintStream;


      public class ClassForName {

        public static void main(String args[]) {
      try {
      Class executeClass = Class.forName("aClass");
      } catch (Throwable e) {
      System.out.println("exception while loading test: " + e);
              return;
      }

        }

      }

      ============================================================ aClass.jasm
      class aClass {

      public static Method "<clinit>":"()V"
      stack 0 locals 0
      {
      aload_0; // error because maxstack==maxlocals==0
      return;
      }

      }

      ========================================================== runtest
      #!/bin/sh

      rm -rf *class

      CLASSPATH=.
      export CLASSPATH

      cmd="javac ClassForName.java"
      echo $cmd; eval $cmd
      cmd="jasm aClass.jasm"
      echo $cmd; eval $cmd

      java -verify ClassForName

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

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

            gbrachasunw Gilad Bracha (Inactive)
            rfqsunw Rfq Rfq (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: