JDK-5019664 : (cl) NoClassDefFoundError when thread is interrupted during class load (sol)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:class_loading
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_8
  • CPU: sparc
  • Submitted: 2004-03-24
  • Updated: 2012-10-08
  • Resolved: 2004-03-26
Related Reports
Duplicate :  
Description

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) 
======================================================================

Comments
WORK AROUND Explicitly load classes at application startup time, that might be used later while a thread is in the interrupted state
11-06-2004

EVALUATION Looks like a duplicate of 4764778. ###@###.### 2004-03-24
24-03-2004