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

Class.forName() allows to load unaccessible classes.

XMLWordPrintable

    • beta
    • sparc
    • solaris_2.5



      Name: akC45999 Date: 11/02/98



      Description of the class java.lang.Class.forName reads:

      Throws:
      LinkageError - if the linkage fails

      As JLS 12.3.3 "Resolution of Symbolic References" states, linking
      includes access checks which throws IllegalAccessError when acces is not permitted.

      However, the follwing simple test shows that Class.forName() does not
      perform access check.

      ------------------------- file resolveClass00705.java
      package javasoft.sqe.tests.vm.constantpool.resolveClass.resolveClass00705;

      import java.io.PrintStream;

      public class resolveClass00705 {

        public static int run(String argv[], PrintStream out) {

      try{
      Class.forName ("javasoft.sqe.tests.vm.constantpool.resolveClass.resolveClass00705.AlienPakage.AlienClass");
      out.println("No exception.");
      return 2/*STATUS_FAILED*/;
      } catch (IllegalAccessError e) {
      return 0/*STATUS_PASSED*/;
      } catch (ThreadDeath e) {
      throw e;
      } catch (Throwable e) {
      out.println("Unexpected exception " + e);
      return 2/*STATUS_FAILED*/;
      }
        }

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

      ------------------------- file resolveClass00705.java
      package javasoft.sqe.tests.vm.constantpool.resolveClass.resolveClass00705.AlienPakage;

      class AlienClass {
      }

      ---------------------------------

      Running the test:

      novo64% java -fullversion
      java full version "JDK-1.2fcs-P"
      novo64% javac -d . AlienClass.java resolveClass00705.java
      novo64% java -verify javasoft.sqe.tests.vm.constantpool.resolveClass.resolveClass00705.resolveClass00705
      No exception.
      novo64%

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

            dkramersunw Douglas Kramer (Inactive)
            rfqsunw Rfq Rfq (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: