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

Class.forName() method allowes invalid fully qualified class name

XMLWordPrintable

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



      Name: szC45993 Date: 01/19/98



      The Java Application Programming Interface, Volume 1, Core Packages,
      says for forName() method (p. 16):
      "PARAMETERS:
      className: the fully qualified name of the desired class."

      ÷ The Java Virtual Machine Specification, chapter 2.7.9 Fully Qualified Names, says (p. 23):
      "Every package, class, interface, array type, and primitive type has a fully qualified
      name. It follows that every type except the null type has a fully qualified name.
      - The fully qualified name of a primitive type is the keyword for that primitive type, namely boolean, char, byte, short, int, long, float, or double.
      - The fully qualified name of a named package that is not a subpackage of a named package is its simple name.
      - The fully qualified name of a named package that is a subpackage of another named package consists of the fully qualified name of the containing package followed by "." followed by the simple (member) name of the subpackage.
      - The fully qualified name of a class or interface that is declared in an unnamed package is the simple name of the class or interface.
      - The fully qualified name of a class or interface that is declared in a named package consists of the fully qualified name of the package followed by "." followed by the simple name of the class or interface.
      - The fully qualified name of an array type consists of the fully qualified name of the component type of the array type followed by "[]".
      "

      So, the JCK execution00301 test below uses invalid fully qualified class
      name (javasoft.sqe.tests.vm/concepts.execution003.execution00301.execution00301a
                                 ^ erroneous symbol
      in execution00301.java) in the java.lang.Class.forName() invocation.
      However, jdk1.2Z does not discover it:

      novo7% setenv CLASSPATH /export/home/JAVA/workdir/classes:/export/home/JAVA/sqe_my/harness_release/classes
      novo7% /export/ld14/java/dest/jdk1.2Z/solaris/bin/java -verify javasoft.sqe.tests.vm.concepts.execution003.execution00301.execution00301
      novo7% echo $status
      97
      novo7%

      The test works fine for jdk1.1.*:

      novo7% setenv CLASSPATH /export/home/JAVA/workdir/classes:/export/home/JAVA/sqe_my/harness_release/classes
      novo7% /export/ld14/java/dest/jdk1.1.1/solaris/bin/java -verify javasoft.sqe.tests.vm.concepts.execution003.execution00301.execution00301
      java.lang.IllegalArgumentException: javasoft.sqe.tests.vm/concepts.execution003.execution00301.execution00301a
      novo7% echo $status
      95
      novo7% /export/ld14/java/dest/jdk1.1.6/solaris/bin/java -verify javasoft.sqe.tests.vm.concepts.execution003.execution00301.execution00301
      java.lang.IllegalArgumentException: javasoft.sqe.tests.vm/concepts.execution003.execution00301.execution00301a
      novo7% echo $status
      95


      SOURCES:

      --------------------- execution00301.java
      //File: @(#)execution00301.java 1.6 97/12/05
      //Copyright 12/05/97 Sun Microsystems, Inc. All Rights Reserved

      package javasoft.sqe.tests.vm.concepts.execution003.execution00301;

      import java.io.PrintStream;

      public class execution00301 {

         public static int run(String argv[], PrintStream out) {
      Class cl = null;

      try{
      cl = Class.forName("javasoft.sqe.tests.vm.concepts.execution003.execution00301.execution00301a");
      cl = Class.forName("javasoft.sqe.tests.vm/concepts.execution003.execution00301.execution00301a");
      // ^ and it's for coverage improvement! DO NOT DELETE!
      }
      catch (java.lang.Throwable e) {
      out.println(e);
      return 0;
      };

      return 2;

        }

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

      }
      --------------------- Intrmdt.java
      //File: @(#)Intrmdt.java 1.1 97/02/25
      //Copyright 02/25/97 Sun Microsystems, Inc. All Rights Reserved

      package javasoft.sqe.tests.vm.concepts.execution003.execution00301;

      public interface execution00301a {

        public abstract void run();

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

      Hook 5(hook5): test

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

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: