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

java.io.RandomAccessFile can cause NoClassDefFoundError

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 1.1.3
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description



      Name: rlT66838 Date: 08/14/97


      PROBLEM DESCRIPTION:
      The small program included below fails with a NoClassDefFoundError.
      It creates 60 threads that each create a RandomAccessFile.
      If the program creates only 20 Threads (20 RandomAccessFile),
      for example, then there is no NoClassDefFoundError.
      Apparently RandomAccessFile is corrupting program memory.
       
      In a much larger version of this program the NoClassDefFoundError
      occurs after "new RandomAccessFile" is called the 30th time.
      Also, in the much larger program the 30th RandomAccessFile call
      fails with an IOException.

      SYSTEM INFO: SunOS 5.5.1 Generic_103640-08 sun4u sparc SUNW,Ultra-2
       
      BUILD INSTRUCTIONS:
      Create a separate build area and copy the following source files to it:
              Churn.java
              ChurnEvent.java
              ChurnThread.java
       
      I ran "jdk1.1.3/bin/javac *.java" to build my Churn program
       
      Run "jdk1.1.3/bin/java Churn" to create 60 files and see the output below.

      OUTPUT of Churn:
      Thread Thread-4 creates filenumber 0
      Thread Thread-5 creates filenumber 1
      java.lang.IllegalArgumentException: mode must be r or rw
      Thread Thread-6 creates filenumber 2
      Thread Thread-7 creates filenumber 3
      Thread Thread-8 creates filenumber 4
      Thread Thread-9 creates filenumber 5
      Thread Thread-10 creates filenumber 6
      Thread Thread-11 creates filenumber 7
      Thread Thread-12 creates filenumber 8
      Thread Thread-13 creates filenumber 9
      Thread Thread-14 creates filenumber 10
      Thread Thread-15 creates filenumber 11
      Thread Thread-16 creates filenumber 12
      Thread Thread-17 creates filenumber 13
      Thread Thread-18 creates filenumber 14
      Thread Thread-19 creates filenumber 15
      Thread Thread-20 creates filenumber 16
      Thread Thread-21 creates filenumber 17
      Thread Thread-22 creates filenumber 18
      Thread Thread-23 creates filenumber 19
      Thread Thread-24 creates filenumber 20
      Thread Thread-25 creates filenumber 21
      Thread Thread-26 creates filenumber 22
      Thread Thread-27 creates filenumber 23
      Thread Thread-28 creates filenumber 24
      Thread Thread-29 creates filenumber 25
      Thread Thread-30 creates filenumber 26
      Thread Thread-31 creates filenumber 27
      Thread Thread-32 creates filenumber 28
      Thread Thread-33 creates filenumber 29
      Thread Thread-34 creates filenumber 30
      Thread Thread-35 creates filenumber 31
      Thread Thread-36 creates filenumber 32
      Thread Thread-37 creates filenumber 33
      Thread Thread-38 creates filenumber 34
      Thread Thread-39 creates filenumber 35
      Thread Thread-40 creates filenumber 36
      Thread Thread-41 creates filenumber 37
      Thread Thread-42 creates filenumber 38
      Thread Thread-43 creates filenumber 39
      Thread Thread-44 creates filenumber 40
      Thread Thread-45 creates filenumber 41
      Thread Thread-46 creates filenumber 42
      Thread Thread-47 creates filenumber 43
      Thread Thread-48 creates filenumber 44
      Thread Thread-49 creates filenumber 45
      Thread Thread-50 creates filenumber 46
      Thread Thread-51 creates filenumber 47
      Thread Thread-52 creates filenumber 48
      Thread Thread-53 creates filenumber 49
      Thread Thread-54 creates filenumber 50
      Thread Thread-55 creates filenumber 51
      Thread Thread-56 creates filenumber 52
      Thread Thread-57 creates filenumber 53
      Thread Thread-58 creates filenumber 54
      Thread Thread-59 creates filenumber 55
      Thread Thread-60 creates filenumber 56
      Thread Thread-61 creates filenumber 57
      Thread Thread-62 creates filenumber 58
      Thread Thread-63 creates filenumber 59
      java.lang.NoClassDefFoundError: ChurnEvent
              at Churn.run(Churn.java:30)
              at Churn.main(Churn.java:12)

      CHURN SOURCE:

      public class Churn implements Runnable {
       
          private ChurnThread churnThread[];
       
          public Churn()
          {
          }
       
          public static void main(String args[])
          {
              Churn churn = new Churn();
              churn.run();
          }
       
          public void run()
          {
              // Create 60 threads that each create a RandomAccessFile
              churnThread = new ChurnThread[60];
       
              for (int i = 0; i < churnThread.length; i++) {
                 churnThread[i] = new ChurnThread(i);
              }
       
              for (int i = 0; i < churnThread.length; i++) {
                      churnThread[i].start();
                      Thread.yield();
              }
       
              // Note that new Integer does not fail with NoClassDefFoundError.
              Integer myInteger = new Integer(0);
       
              // Note that new ChurnEvent (a class that is not extended) fails
              // with NoClassDefFoundError.
              ChurnEvent churnEvent = new ChurnEvent();
       
              try {
                      Thread.sleep(10000);
              } catch(InterruptedException e) { ; }
       
              System.exit(0);
          }
      }

      import java.io.*;
      class ChurnThread extends Thread
      {
              RandomAccessFile churn_raf;
              int filenumber;
       
              public ChurnThread(int f)
              {
                      filenumber = f;
              }
       
              public void run()
              {
                  System.out.println("Thread " + Thread.currentThread().getName() + "
      creates filenumber " + filenumber);
                  if (filenumber == 1) {
                      // Cause an exception to happen by constructing
                      // a RandomAccessFile with a bad mode.
                      // Actually, you don't even need to make an
                      // IllegalArgumentException happen in order to see
                      // the NoClassDefFoundError in thread named "main"
                      // in this small version of a larger program.
                      // The larger version of this program gets an
                      // IOException the 30th time RandomAccessFile is
                      // constructed. So it appears that the size of the
                      // program determines when and how RandomAccessFile
                      // corrupts the program's memory.
                      try {
                              churn_raf = new
      RandomAccessFile(Integer.toString(filenumber), "z");
                      } catch (IOException e) {
                              System.out.println(e.toString());
                              stop();
                      } catch (IllegalArgumentException e) {
                              System.out.println(e.toString());
                              stop();
                      }
                  } else {
                      try {
                              churn_raf = new
      RandomAccessFile(Integer.toString(filenumber), "rw");
                      } catch (IOException e) {
                              stop();
                      }
                  }
       
                  try {
                      Thread.sleep(10000);
                  } catch(InterruptedException e) { ; }
              }
      }

      class ChurnEvent
      {
              public ChurnEvent()
              {
              }
      }




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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mr Mark Reinhold
              Reporter:
              rlewis Roger Lewis (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: