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

Class.forName appears to cache initialization attempts

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.4.0, 1.4.1, 1.4.2
    • Fix Version/s: None
    • Component/s: core-libs

      Description



      Name: skR10005 Date: 08/30/2002


      The following JCK1.4a test
      api/java_lang/Class/index.html#ForName2[Class2158]
      api/java_lang/Class/index.html#ForName2[Class2166]
      fails on jdk1.4.0 under plugin.

      Java API spec for method Class.forName reads:
        "ExceptionInInitializerError - if the initialization provoked by this method
         fails"

      But implementation throws java.lang.NoClassDefFoundError.

      It looks like class loader cashes not loaded class
      but the reason is not taken into account.

      To reproduce the failure do the following:
      1) create java & html files in the same directory.
      ================test.java===================
      public class test extends java.applet.Applet {
          public void start() {
              try {
                  Class.forName("Noninitializable");
              } catch(ClassNotFoundException e) {
                  System.out.println("" + e);
                  return;
              } catch(ExceptionInInitializerError eiie) {
                  System.out.println( "OKAY" );
              }
              try {
                  Class.forName("Noninitializable");
              } catch(ClassNotFoundException e) {
                  System.out.println("" + e);
                  return;
              } catch(ExceptionInInitializerError eiie) {
                  System.out.println( "OKAY" );
              }
              System.out.println("ExceptionInInitializerError is not thrown");
          }
      }

      class Noninitializable {
          static int i = 1/0;
      }
      ================test.html===================
      <html>
      <APPLET code="test.class" codebase="." width="500" height="500">Java
      applet.</APPLET>
      </html>
      ============================================
      2) compile java source
      $javac -d . test.java
      3) run appletviewer
      $appletviewer -J-showversion ./test.html
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      OKAY
      java.lang.NoClassDefFoundError
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Class.java:130)
              at test.start(test.java:12)
              at sun.applet.AppletPanel.run(AppletPanel.java:355)
              at java.lang.Thread.run(Thread.java:536)

      That is the first attempt to load class passed (correct exception is thrown).
      The second one is failed.

      Note that jdk1.4.1, jdk1.4.2 have the same problems:

      $ appletviewer -J-showversion ./test.html
      java version "1.4.1-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b20)
      Java HotSpot(TM) Client VM (build 1.4.1-rc-b20, mixed mode)

      OKAY
      java.lang.NoClassDefFoundError
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Class.java:140)
              at test.start(test.java:12)
              at sun.applet.AppletPanel.run(AppletPanel.java:370)
              at java.lang.Thread.run(Thread.java:536)

      $ appletviewer -J-showversion ./test.html
      java version "1.4.2-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b01)
      Java HotSpot(TM) Client VM (build 1.4.2-beta-b01, mixed mode)

      OKAY
      java.lang.NoClassDefFoundError
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Class.java:140)
              at test.start(test.java:12)
              at sun.applet.AppletPanel.run(AppletPanel.java:370)
              at java.lang.Thread.run(Thread.java:536)

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

        Attachments

          Activity

            People

            Assignee:
            iris Iris Clark
            Reporter:
            serjsunw Serj Serj (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: