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

valid class is loaded twice after loading an invalid class.

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2fcs
    • CPU:
      sparc
    • OS:
      solaris_2.4
    • Verification:
      Verified

      Description



      Name: akC45999 Date: 09/28/98



      Section 5.3.1 Loading Using the Default Class Loader

      of the JVMS reads:

      First, the Java virtual machine determines whether a class or interface
      named N has been loaded by the default class loader. If so, this class
      is C, and no class creation is necessary.

      However, the default classloader can load a valid class twice if

      a) it was first asked to load an invalid class and
      b) the garbage collector has been run

      To reproduce compile following 2 source files and run
       java -verbose defaultLoader00102

      The tail of the trace shows that the class defaultLoader00102
      was loaded twice:

      ...
      [Loaded defaultLoader00102]
      initializing class defaultLoader00102
      [Loaded BadInterface]
      [Loaded java.lang.ClassCircularityError from java/lang/ClassCircularityError.class]
      Throwable:java.lang.ClassCircularityError: BadInterface
      [Loaded clss2]
      [Loaded defaultLoader00102]
      initializing class defaultLoader00102
      check 3: str 1=modified string
      str 2=initial string
      failed

      Note also, if at least one of calls to check(1,out) or check(2,out)
      is not commented, then the test passes.

      The bug is discovered when using JDK 1.2fcsI ... 1.2fcsL.

      // -------------------------- BadInterface.jasm
      public interface BadInterface extends BadInterface {}
      // -------------------------- end BadInterface.jasm

      // -------------------------- defaultLoader00102.java
      import java.io.PrintStream;


      class clss2 {

        public static String getStr() {
      return defaultLoader00102.str;
        }

      }


      public class defaultLoader00102 {

        static String str="initial string";
        static {
      System.out.println("initializing class defaultLoader00102");
        }

        static boolean check(int n, PrintStream out) {
      String str2=clss2.getStr();
      out.print("check "+n+": ");
      if (str2!=defaultLoader00102.str) {
      out.println("str 1=" + defaultLoader00102.str);
      out.println("str 2=" + str2);
      out.println("failed");
      return true;
      }
      out.println("passed");
      return false;
        }

        public static int run(String argv[], PrintStream out) {
          str="modified string";
      // if (check(1, out)) return 2;
      try {
      Class.forName("BadInterface");
      } catch (Throwable e) {
      out.println("Throwable:" + e);
      }
      // if (check(2, out)) return 2;
      Runtime.getRuntime().gc();
      if (check(3, out)) return 2;
      return 0;
        }

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


      // -------------------------- end defaultLoader00102.java

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

      Name: akC45999 Date: 09/28/98


      The bug was introduced in JDK 1.2fcsD. JDK 1.2fcsC passes the test.

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

        Attachments

          Activity

            People

            • Assignee:
              sliangsunw Sheng Liang (Inactive)
              Reporter:
              rfqsunw Rfq Rfq (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: