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

(cl) NoClassDefFoundError when thread is interrupted during class load (sol)

XMLWordPrintable

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



      Name: jl125535 Date: 03/24/2004


      FULL PRODUCT VERSION :
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
      Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

      (also 1.4.1 and 1.5.0-beta-32c)


      ADDITIONAL OS VERSION INFORMATION :
      SunOS 5.8
      Problem does not occur on Windows JVM, or with Solaris server JVM.

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      running on a Sun Blade 100

      A DESCRIPTION OF THE PROBLEM :
      ClassLoader can fail if it tries to load a class after/from a thread that has been interrupted.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Procedure:

      1. Run (The word "BEGIN" should appear on System.out).
      2. Click Cancel Button.
      3. The following error message appears:


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      BEGIN
      LoadThis.f()
      END

      ACTUAL -
      java.lang.NoClassDefFoundError: Bug$MyThread$LoadThis
              at Bug$MyThread.run(Bug.java:67)
      (This error might not occur on every execution.)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.NoClassDefFoundError: Bug$MyThread$LoadThis
              at Bug$MyThread.run(Bug.java:67)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.awt.BorderLayout;

      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      import javax.swing.JFrame;
      import javax.swing.JButton;

      public final class Bug
      {
        private Bug() { }

        public static void main(String[] argv)
        {
          final MyThread t = new MyThread();

          JButton cancel = new JButton("Cancel");
          cancel.addActionListener(new ActionListener()
          {
            public void actionPerformed(ActionEvent e)
            {
              t.setCanceled();
              t.interrupt();
            }
          });

          JFrame frame = new JFrame("Bug");
          frame.getContentPane().add(cancel, BorderLayout.NORTH);
          frame.pack();
          frame.setVisible(true);

          t.start();
        }

        private static final class MyThread extends Thread
        {
          private boolean isCanceled;

          MyThread() { }

          synchronized void setCanceled() { isCanceled = true; }

          private synchronized boolean isCanceled() { return isCanceled; }

          public void run()
          {
            System.out.println("BEGIN");
            while (!isCanceled());

            LoadThis.f();

            System.out.println("END");
            System.exit(0);
          }

          private static final class LoadThis
          {
            static void f() { System.out.println("LoadThis.f()"); }
          }
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Don't use Thread.interrupt().
      (Incident Review ID: 244267)
      ======================================================================

            iris Iris Clark
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: