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

Question on Class.forName(String)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • core-libs



      Name: vi73552 Date: 03/10/99


      When I try to pass null as a argument to Class.forName()
      method, it works fine under JDK1.1.6 if I catch
      IllegalArgumentException, but throws NullPointerException
      in JDK1.2. So the code I have written runs under JDK1.1.6
      while not under JDK1.2.

      The source code is :
      class TestStr
      {
      public static void main(String[] args)
      {
      System.out.println("Success");
      try
      {
      Class.forName(null);
      }
      catch(ClassNotFoundException e)
      {
      System.out.println( e );
      e.printStackTrace();
      }
      catch (IllegalArgumentException ex)
      {
      System.out.println( e );
      }
      System.out.println("Success");
      }
      }

      Exact Text of Error Message :
         Exception in Thread "main" java.lang.NullPointerException
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Class.java:124)
            at TestStr.main(TestStr.java:8).

      Output of java -fullversion command :
          JDK-1.2-V.
      (Review ID: 55294)
      ======================================================================

            apalanissunw Anand Palaniswamy (Inactive)
            vasya Vassili Igouchkine (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: